1
0
mirror of https://github.com/libuv/libuv synced 2025-03-28 21:13:16 +00:00

win,spawn: allow %PATH% to be unset (#4116)

Fix: https://github.com/libuv/libuv/issues/4115
This commit is contained in:
Kyle Edwards 2023-08-14 15:25:11 -04:00 committed by GitHub
parent 2f82750098
commit c97017dd1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 16 deletions

View File

@ -396,7 +396,7 @@ static WCHAR* search_path(const WCHAR *file,
name_has_ext);
while (result == NULL) {
if (*dir_end == L'\0') {
if (dir_end == NULL || *dir_end == L'\0') {
break;
}
@ -1025,22 +1025,19 @@ int uv_spawn(uv_loop_t* loop,
DWORD path_len, r;
path_len = GetEnvironmentVariableW(L"PATH", NULL, 0);
if (path_len == 0) {
err = GetLastError();
goto done;
}
if (path_len != 0) {
alloc_path = (WCHAR*) uv__malloc(path_len * sizeof(WCHAR));
if (alloc_path == NULL) {
err = ERROR_OUTOFMEMORY;
goto done;
}
path = alloc_path;
alloc_path = (WCHAR*) uv__malloc(path_len * sizeof(WCHAR));
if (alloc_path == NULL) {
err = ERROR_OUTOFMEMORY;
goto done;
}
path = alloc_path;
r = GetEnvironmentVariableW(L"PATH", path, path_len);
if (r == 0 || r >= path_len) {
err = GetLastError();
goto done;
r = GetEnvironmentVariableW(L"PATH", path, path_len);
if (r == 0 || r >= path_len) {
err = GetLastError();
goto done;
}
}
}

View File

@ -504,6 +504,7 @@ TEST_DECLARE (listen_with_simultaneous_accepts)
TEST_DECLARE (listen_no_simultaneous_accepts)
TEST_DECLARE (fs_stat_root)
TEST_DECLARE (spawn_with_an_odd_path)
TEST_DECLARE (spawn_no_path)
TEST_DECLARE (ipc_listen_after_bind_twice)
TEST_DECLARE (win32_signum_number)
#else
@ -1021,6 +1022,7 @@ TASK_LIST_START
TEST_ENTRY (listen_no_simultaneous_accepts)
TEST_ENTRY (fs_stat_root)
TEST_ENTRY (spawn_with_an_odd_path)
TEST_ENTRY (spawn_no_path)
TEST_ENTRY (ipc_listen_after_bind_twice)
TEST_ENTRY (win32_signum_number)
#else

View File

@ -1366,6 +1366,34 @@ TEST_IMPL(spawn_with_an_odd_path) {
MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0;
}
TEST_IMPL(spawn_no_path) {
char* env[1];
WCHAR* old_path = NULL;
DWORD old_path_len;
if ((old_path_len = GetEnvironmentVariableW(L"PATH", NULL, 0)) > 0) {
old_path = malloc(old_path_len * sizeof(WCHAR));
GetEnvironmentVariableW(L"PATH", old_path, old_path_len);
SetEnvironmentVariableW(L"PATH", NULL);
}
init_process_options("spawn_helper1", exit_cb);
options.env = env;
env[0] = NULL;
ASSERT(0 == uv_spawn(uv_default_loop(), &process, &options));
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT));
ASSERT(exit_cb_called == 1);
ASSERT(close_cb_called == 1);
SetEnvironmentVariableW(L"PATH", old_path);
MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0;
}
#endif
#ifndef _WIN32