Martin Storsjo : ntdll: Only call putenv() if we are going to call exec().

Alexandre Julliard julliard at winehq.org
Fri Aug 14 16:39:32 CDT 2020


Module: wine
Branch: master
Commit: e8f2c2464a3ce47e84be7786691ba35d25c7e6a8
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=e8f2c2464a3ce47e84be7786691ba35d25c7e6a8

Author: Martin Storsjo <martin at martin.st>
Date:   Fri Aug 14 14:34:51 2020 +0300

ntdll: Only call putenv() if we are going to call exec().

If we aren't going to exec (if pre_exec() returns zero), we will
continue using the envp pointer we got from the caller. However,
the putenv() call does update the environment, and this can in
some cases overwrite the array that the old (stale, potentially
dangling) envp pointer points to.

Signed-off-by: Martin Storsjo <martin at martin.st>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/unix/loader.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c
index d621d4ef8e..e7cc050ba9 100644
--- a/dlls/ntdll/unix/loader.c
+++ b/dlls/ntdll/unix/loader.c
@@ -1685,14 +1685,14 @@ void __wine_main( int argc, char *argv[], char *envp[] )
 
     if (!getenv( "WINELOADERNOEXEC" ))  /* first time around */
     {
-        static char noexec[] = "WINELOADERNOEXEC=1";
-
-        putenv( noexec );
         check_command_line( argc, argv );
         if (pre_exec())
         {
+            static char noexec[] = "WINELOADERNOEXEC=1";
             char **new_argv = malloc( (argc + 2) * sizeof(*argv) );
+
             memcpy( new_argv + 1, argv, (argc + 1) * sizeof(*argv) );
+            putenv( noexec );
             loader_exec( argv0, new_argv, client_cpu );
             fatal_error( "could not exec the wine loader\n" );
         }




More information about the wine-cvs mailing list