From 602a02995a3da29033b3f845f12dc72f82a5151f Mon Sep 17 00:00:00 2001 From: Vivian Thiebaut <81188381+vthiebaut10@users.noreply.github.com> Date: Mon, 7 Feb 2022 18:00:39 -0500 Subject: [PATCH] Handle Path Variable: Prepend System path to User path (#563) --- contrib/win32/openssh/bash_tests_iterator.ps1 | 6 +++--- contrib/win32/win32compat/w32-doexec.c | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/contrib/win32/openssh/bash_tests_iterator.ps1 b/contrib/win32/openssh/bash_tests_iterator.ps1 index bee73f134..cdf60f2a3 100644 --- a/contrib/win32/openssh/bash_tests_iterator.ps1 +++ b/contrib/win32/openssh/bash_tests_iterator.ps1 @@ -24,7 +24,7 @@ if ($TestFilePath) { # convert to bash format $TestFilePath = $TestFilePath -replace "\\","/" } -$OriginalUserPath = [System.Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::User) +$OriginalSystemPath = [System.Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::Machine) # Make sure config.h exists. It is used in some bashstests (Ex - sftp-glob.sh, cfgparse.sh) # first check in $BashTestsPath folder. If not then it's parent folder. If not then in the $OpenSSHBinPath @@ -104,7 +104,7 @@ try # Prepend shell path to User PATH in the registry so that SSHD authenticated child process can inherit it. # We can probably delete the logic above to add it to the process PATH, but there is no need. - [System.Environment]::SetEnvironmentVariable('Path', $TEST_SHELL_DIR + ";" + $OriginalUserPath, [System.EnvironmentVariableTarget]::User) + [System.Environment]::SetEnvironmentVariable('Path', $TEST_SHELL_DIR + ";" + $OriginalSystemPath, [System.EnvironmentVariableTarget]::Machine) $BashTestsPath = $BashTestsPath -replace "\\","/" Push-location $BashTestsPath @@ -260,7 +260,7 @@ try finally { # Restore User Path variable in the registry once the tests finish running. - [System.Environment]::SetEnvironmentVariable('Path', $OriginalUserPath, [System.EnvironmentVariableTarget]::User) + [System.Environment]::SetEnvironmentVariable('Path', $OriginalSystemPath, [System.EnvironmentVariableTarget]::Machine) # remove temp test directory if (!$SkipCleanup) { diff --git a/contrib/win32/win32compat/w32-doexec.c b/contrib/win32/win32compat/w32-doexec.c index a4991e508..64c49d698 100644 --- a/contrib/win32/win32compat/w32-doexec.c +++ b/contrib/win32/win32compat/w32-doexec.c @@ -196,14 +196,14 @@ setup_session_user_vars(wchar_t* profile_path) } } - /* Path is a special case. The System Path value is appended to the User Path value */ + /* Path is a special case. The System Path value is preppended to the User Path value */ if (_wcsicmp(name, L"PATH") == 0 && j == 1) { if ((required = GetEnvironmentVariableW(L"PATH", NULL, 0)) != 0) { - size_t user_path_size = wcslen(to_apply); - path_value = xmalloc((required + user_path_size + 2) * 2); - GOTO_CLEANUP_ON_ERR(memcpy_s(path_value, (user_path_size + 1) * 2, to_apply, (user_path_size + 1) * 2)); - path_value[user_path_size] = L';'; - GetEnvironmentVariableW(L"PATH", path_value + user_path_size + 1, required); + size_t user_path_size = wcslen(to_apply) + 1; + path_value = xmalloc((required + user_path_size) * 2); + GetEnvironmentVariableW(L"PATH", path_value, required); + path_value[required - 1] = L';'; + GOTO_CLEANUP_ON_ERR(memcpy_s(path_value + required, user_path_size * 2, to_apply, user_path_size * 2)); to_apply = path_value; } }