Alexandre Julliard : ntdll: Explicitly reset the PATH variable before reloading the environment.

Alexandre Julliard julliard at winehq.org
Tue Mar 9 14:55:19 CST 2021


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Mar  9 15:06:58 2021 +0100

ntdll: Explicitly reset the PATH variable before reloading the environment.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50786
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/unix/env.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/dlls/ntdll/unix/env.c b/dlls/ntdll/unix/env.c
index 004e76b789f..2051ad33888 100644
--- a/dlls/ntdll/unix/env.c
+++ b/dlls/ntdll/unix/env.c
@@ -1306,7 +1306,7 @@ static WCHAR *expand_value( WCHAR *env, SIZE_T size, const WCHAR *src, SIZE_T sr
  * helper for add_registry_environment().
  * Note that Windows happily truncates the value if it's too big.
  */
-static void add_registry_variables( WCHAR **env, SIZE_T *pos, SIZE_T *size, HANDLE key, BOOL append )
+static void add_registry_variables( WCHAR **env, SIZE_T *pos, SIZE_T *size, HANDLE key )
 {
     static const WCHAR pathW[] = {'P','A','T','H'};
     NTSTATUS status;
@@ -1331,13 +1331,13 @@ static void add_registry_variables( WCHAR **env, SIZE_T *pos, SIZE_T *size, HAND
         if (info->Type == REG_EXPAND_SZ) value = expand_value( *env, *pos, data, datalen );
 
         /* PATH is magic */
-        if (append && namelen == 4 && !wcsnicmp( info->Name, pathW, 4 ) && (p = find_env_var( *env, *pos, pathW, 4 )))
+        if (namelen == 4 && !wcsnicmp( info->Name, pathW, 4 ) && (p = find_env_var( *env, *pos, pathW, 4 )))
         {
             static const WCHAR sepW[] = {';',0};
-            WCHAR *newpath = malloc( (wcslen(p) - 4 + datalen) * sizeof(WCHAR) );
+            WCHAR *newpath = malloc( (wcslen(p) - 3 + wcslen(value)) * sizeof(WCHAR) );
             wcscpy( newpath, p + 5 );
             wcscat( newpath, sepW );
-            wcscat( newpath, data );
+            wcscat( newpath, value );
             if (value != data) free( value );
             value = newpath;
         }
@@ -1370,17 +1370,17 @@ static void add_registry_environment( WCHAR **env, SIZE_T *pos, SIZE_T *size )
     init_unicode_string( &nameW, syskeyW );
     if (!NtOpenKey( &key, KEY_READ, &attr ))
     {
-        add_registry_variables( env, pos, size, key, FALSE );
+        add_registry_variables( env, pos, size, key );
         NtClose( key );
     }
     if (!open_hkcu_key( "Environment", &key ))
     {
-        add_registry_variables( env, pos, size, key, TRUE );
+        add_registry_variables( env, pos, size, key );
         NtClose( key );
     }
     if (!open_hkcu_key( "Volatile Environment", &key ))
     {
-        add_registry_variables( env, pos, size, key, TRUE );
+        add_registry_variables( env, pos, size, key );
         NtClose( key );
     }
 }
@@ -1708,18 +1708,28 @@ static inline void put_unicode_string( WCHAR *src, WCHAR **dst, UNICODE_STRING *
  */
 static RTL_USER_PROCESS_PARAMETERS *build_initial_params(void)
 {
+    static const WCHAR pathW[] = {'P','A','T','H'};
     RTL_USER_PROCESS_PARAMETERS *params = NULL;
     SIZE_T size, env_pos, env_size;
-    WCHAR *dst;
+    WCHAR *dst, *p, *path = NULL;
     WCHAR *cmdline = build_command_line( main_wargv + 1 );
     WCHAR *env = get_initial_environment( &env_pos, &env_size );
     NTSTATUS status;
 
+    /* store the initial PATH value */
+    if ((p = find_env_var( env, env_pos, pathW, 4 )))
+    {
+        path = malloc( (wcslen(p + 5) + 1) * sizeof(WCHAR) );
+        wcscpy( path, p + 5 );
+    }
     add_dynamic_environment( &env, &env_pos, &env_size );
     add_registry_environment( &env, &env_pos, &env_size );
     env[env_pos] = 0;
     run_wineboot( env, env_pos );
+
     /* reload environment now that wineboot has run */
+    set_env_var( &env, &env_pos, &env_size, pathW, 4, path );  /* reset PATH */
+    free( path );
     add_registry_environment( &env, &env_pos, &env_size );
     env[env_pos++] = 0;
 




More information about the wine-cvs mailing list