This patch causes a segfault in the event that __wine_main_argv is not the argv that got passed to main. This happened in a program I wrote that acts as a custom wine loader. It creates an argv by using malloc, then passes that to wine_init.
Why wouldn’t setprogname(argv[1]) be adequate?
~Theodore
> On Feb 19, 2016, at 2:33 PM, Charles Davis <cdavis5x(a)gmail.com> wrote:
>
> Signed-off-by: Charles Davis <cdavis5x(a)gmail.com>
> ---
> Try 2:
> * Clean up the #ifdefs a bit. (I'm not happy about the duplicated code, though.)
> * Don't copy the progname into a static array. There's no need; the argument vector lasts as long as the process itself. (I suppose I was being overly defensive with that.)
>
> configure.ac | 1 +
> dlls/kernel32/process.c | 17 ++++++++++++++---
> 2 files changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index c9445e7..2ebbb10 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -2026,6 +2026,7 @@ AC_CHECK_FUNCS(\
> sched_yield \
> select \
> setproctitle \
> + setprogname \
> setrlimit \
> settimeofday \
> sigaltstack \
> diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
> index 86333be..4771108 100644
> --- a/dlls/kernel32/process.c
> +++ b/dlls/kernel32/process.c
> @@ -1118,9 +1118,20 @@ static void set_process_name( int argc, char *argv[] )
> {
> #ifdef HAVE_SETPROCTITLE
> setproctitle("-%s", argv[1]);
> -#endif
> + /* remove argv[0] */
> + memmove( argv, argv + 1, argc * sizeof(argv[0]) );
> +#elif defined(HAVE_SETPROGNAME)
> + int i, offset;
> + char *end = argv[argc-1] + strlen(argv[argc-1]) + 1;
>
> -#ifdef HAVE_PRCTL
> + offset = argv[1] - argv[0];
> + memmove( argv[1] - offset, argv[1], end - argv[1] );
> + memset( end - offset, 0, offset );
> + for (i = 1; i < argc; i++) argv[i-1] = argv[i] - offset;
> + argv[i-1] = NULL;
> +
> + setprogname( argv[0] );
> +#elif defined(HAVE_PRCTL)
> int i, offset;
> char *p, *prctl_name = argv[1];
> char *end = argv[argc-1] + strlen(argv[argc-1]) + 1;
> @@ -1141,11 +1152,11 @@ static void set_process_name( int argc, char *argv[] )
> argv[i-1] = NULL;
> }
> else
> -#endif /* HAVE_PRCTL */
> {
> /* remove argv[0] */
> memmove( argv, argv + 1, argc * sizeof(argv[0]) );
> }
> +#endif /* HAVE_PRCTL */
> }
>
>
> --
> 2.7.1
>
>
>