libuv: win,spawn: allow %PATH% to be unset

Backport libuv commit `c97017dd` (win,spawn: allow `%PATH%` to be unset,
2023-08-14).

See https://github.com/libuv/libuv/pull/4116.
This commit is contained in:
Kyle Edwards 2023-08-02 12:36:27 -04:00 committed by Brad King
parent 703e3e03c3
commit 5fb17a1410

View File

@ -394,7 +394,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;
}
@ -1027,22 +1027,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;
}
}
}