win, process: support semicolons in PATH variable

Fixes a bug that would cause libuv to crash when PATH environment
variable contained paths with semicolon in it

Refs: https://github.com/nodejs/help/issues/728
Fixes: https://github.com/libuv/libuv/issues/1422
PR-URL: https://github.com/libuv/libuv/pull/1438
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
Bartosz Sosnowski 2017-07-27 12:34:31 +02:00
parent cf6d047e84
commit cbcf13af6a
3 changed files with 36 additions and 1 deletions

View File

@ -405,8 +405,15 @@ static WCHAR* search_path(const WCHAR *file,
/* Next slice starts just after where the previous one ended */
dir_start = dir_end;
/* If path is quoted, find quote end */
if (*dir_start == L'"' || *dir_start == L'\'') {
dir_end = wcschr(dir_start + 1, *dir_start);
if (dir_end == NULL) {
dir_end = wcschr(dir_start, L'\0');
}
}
/* Slice until the next ; or \0 is found */
dir_end = wcschr(dir_start, L';');
dir_end = wcschr(dir_end, L';');
if (dir_end == NULL) {
dir_end = wcschr(dir_start, L'\0');
}

View File

@ -256,6 +256,7 @@ TEST_DECLARE (spawn_auto_unref)
TEST_DECLARE (spawn_closed_process_io)
TEST_DECLARE (spawn_reads_child_path)
TEST_DECLARE (spawn_inherit_streams)
TEST_DECLARE (spawn_quoted_path)
TEST_DECLARE (fs_poll)
TEST_DECLARE (fs_poll_getpath)
TEST_DECLARE (kill)
@ -723,6 +724,7 @@ TASK_LIST_START
TEST_ENTRY (spawn_closed_process_io)
TEST_ENTRY (spawn_reads_child_path)
TEST_ENTRY (spawn_inherit_streams)
TEST_ENTRY (spawn_quoted_path)
TEST_ENTRY (fs_poll)
TEST_ENTRY (fs_poll_getpath)
TEST_ENTRY (kill)

View File

@ -1,3 +1,4 @@
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@ -1711,6 +1712,31 @@ TEST_IMPL(spawn_inherit_streams) {
return 0;
}
TEST_IMPL(spawn_quoted_path) {
#ifndef _WIN32
RETURN_SKIP("Test for Windows")
#else
char* quoted_path_env[2];
options.file = "not_existing";
args[0] = options.file;
args[1] = NULL;
options.args = args;
options.exit_cb = exit_cb;
options.flags = 0;
/* We test if search_path works correctly with semicolons in quoted path. */
/* We will use invalid drive, so we are sure no executable is spawned */
quoted_path_env[0] = "PATH=\"xyz:\\test;\";xyz:\\other";
quoted_path_env[1] = NULL;
options.env = quoted_path_env;
/* We test if libuv will not segfault. */
uv_spawn(uv_default_loop(), &process, &options);
MAKE_VALGRIND_HAPPY();
return 0;
#endif
}
/* Helper for child process of spawn_inherit_streams */
#ifndef _WIN32
int spawn_stdin_stdout(void) {