Skip to content

Commit 4cfd64e

Browse files
committed
uv: upgrade to abc945b
1 parent 69d8e77 commit 4cfd64e

File tree

1 file changed

+64
-37
lines changed

1 file changed

+64
-37
lines changed

deps/uv/src/win/process.c

Lines changed: 64 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
typedef struct env_var {
3838
const char* narrow;
3939
const WCHAR* wide;
40-
int len; /* including null or '=' */
40+
size_t len; /* including null or '=' */
41+
DWORD value_len;
4142
int supplied;
42-
int value_len;
4343
} env_var_t;
4444

4545
#define E_V(str) { str "=", L##str, sizeof(str), 0, 0 }
@@ -102,13 +102,13 @@ static void uv_process_init(uv_loop_t* loop, uv_process_t* handle) {
102102
* Helper function for search_path
103103
*/
104104
static WCHAR* search_path_join_test(const WCHAR* dir,
105-
int dir_len,
106-
const WCHAR* name,
107-
int name_len,
108-
const WCHAR* ext,
109-
int ext_len,
110-
const WCHAR* cwd,
111-
int cwd_len) {
105+
size_t dir_len,
106+
const WCHAR* name,
107+
size_t name_len,
108+
const WCHAR* ext,
109+
size_t ext_len,
110+
const WCHAR* cwd,
111+
size_t cwd_len) {
112112
WCHAR *result, *result_pos;
113113
DWORD attrs;
114114

@@ -193,12 +193,12 @@ static WCHAR* search_path_join_test(const WCHAR* dir,
193193
* Helper function for search_path
194194
*/
195195
static WCHAR* path_search_walk_ext(const WCHAR *dir,
196-
int dir_len,
197-
const WCHAR *name,
198-
int name_len,
199-
WCHAR *cwd,
200-
int cwd_len,
201-
int name_has_ext) {
196+
size_t dir_len,
197+
const WCHAR *name,
198+
size_t name_len,
199+
WCHAR *cwd,
200+
size_t cwd_len,
201+
int name_has_ext) {
202202
WCHAR* result;
203203

204204
/* If the name itself has a nonempty extension, try this extension first */
@@ -281,11 +281,11 @@ static WCHAR* search_path(const WCHAR *file,
281281
WCHAR *file_name_start;
282282
WCHAR *dot;
283283
const WCHAR *dir_start, *dir_end, *dir_path;
284-
int dir_len;
284+
size_t dir_len;
285285
int name_has_ext;
286286

287-
int file_len = wcslen(file);
288-
int cwd_len = wcslen(cwd);
287+
size_t file_len = wcslen(file);
288+
size_t cwd_len = wcslen(cwd);
289289

290290
/* If the caller supplies an empty filename,
291291
* we're not gonna return c:\windows\.exe -- GFY!
@@ -380,8 +380,9 @@ static WCHAR* search_path(const WCHAR *file,
380380
* Returns a pointer to the end (next char to be written) of the buffer
381381
*/
382382
WCHAR* quote_cmd_arg(const WCHAR *source, WCHAR *target) {
383-
int len = wcslen(source),
384-
i, quote_hit;
383+
size_t len = wcslen(source);
384+
size_t i;
385+
int quote_hit;
385386
WCHAR* start;
386387

387388
/*
@@ -512,7 +513,7 @@ uv_err_t make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr)
512513
*arg,
513514
-1,
514515
temp_buffer,
515-
dst + dst_len - pos);
516+
(int) (dst + dst_len - pos));
516517
if (arg_len == 0) {
517518
goto error;
518519
}
@@ -548,10 +549,10 @@ uv_err_t make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr)
548549
* issues associated with that solution; this is the caller's
549550
* char**, and modifying it is rude.
550551
*/
551-
static void check_required_vars_contains_var(env_var_t* required, int size,
552+
static void check_required_vars_contains_var(env_var_t* required, int count,
552553
const char* var) {
553554
int i;
554-
for (i = 0; i < size; ++i) {
555+
for (i = 0; i < count; ++i) {
555556
if (_strnicmp(required[i].narrow, var, required[i].len) == 0) {
556557
required[i].supplied = 1;
557558
return;
@@ -571,11 +572,11 @@ static void check_required_vars_contains_var(env_var_t* required, int size,
571572
* these get defined if the input environment block does not contain any
572573
* values for them.
573574
*/
574-
WCHAR* make_program_env(char** env_block) {
575+
uv_err_t make_program_env(char* env_block[], WCHAR** dst_ptr) {
575576
WCHAR* dst;
576577
WCHAR* ptr;
577578
char** env;
578-
int env_len = 1 * sizeof(WCHAR); /* room for closing null */
579+
size_t env_len = 1; /* room for closing null */
579580
int len;
580581
int i;
581582
DWORD var_size;
@@ -587,36 +588,53 @@ WCHAR* make_program_env(char** env_block) {
587588
};
588589

589590
for (env = env_block; *env; env++) {
591+
int len;
590592
check_required_vars_contains_var(required_vars,
591593
ARRAY_SIZE(required_vars),
592594
*env);
593-
env_len += (uv_utf8_to_utf16(*env, NULL, 0) * sizeof(WCHAR));
595+
596+
len = MultiByteToWideChar(CP_UTF8,
597+
0,
598+
*env,
599+
-1,
600+
NULL,
601+
0);
602+
if (len <= 0) {
603+
return uv__new_sys_error(GetLastError());
604+
}
605+
606+
env_len += len;
594607
}
595608

596609
for (i = 0; i < ARRAY_SIZE(required_vars); ++i) {
597610
if (!required_vars[i].supplied) {
598-
env_len += required_vars[i].len * sizeof(WCHAR);
611+
env_len += required_vars[i].len;
599612
var_size = GetEnvironmentVariableW(required_vars[i].wide, NULL, 0);
600613
if (var_size == 0) {
601-
uv_fatal_error(GetLastError(), "GetEnvironmentVariableW");
614+
return uv__new_sys_error(GetLastError());
602615
}
603-
required_vars[i].value_len = (int)var_size;
604-
env_len += (int)var_size * sizeof(WCHAR);
616+
required_vars[i].value_len = var_size;
617+
env_len += var_size;
605618
}
606619
}
607620

608-
dst = malloc(env_len);
621+
dst = malloc(env_len * sizeof(WCHAR));
609622
if (!dst) {
610-
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
623+
return uv__new_artificial_error(UV_ENOMEM);
611624
}
612625

613626
ptr = dst;
614627

615628
for (env = env_block; *env; env++, ptr += len) {
616-
len = uv_utf8_to_utf16(*env, ptr, (size_t)(env_len - (ptr - dst)));
617-
if (!len) {
629+
len = MultiByteToWideChar(CP_UTF8,
630+
0,
631+
*env,
632+
-1,
633+
ptr,
634+
(int) (env_len - (ptr - dst)));
635+
if (len <= 0) {
618636
free(dst);
619-
return NULL;
637+
return uv__new_sys_error(GetLastError());
620638
}
621639
}
622640

@@ -635,8 +653,11 @@ WCHAR* make_program_env(char** env_block) {
635653
}
636654
}
637655

656+
/* Terminate with an extra NULL. */
638657
*ptr = L'\0';
639-
return dst;
658+
659+
*dst_ptr = dst;
660+
return uv_ok_;
640661
}
641662

642663

@@ -739,7 +760,7 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
739760
WCHAR* path = NULL;
740761
BOOL result;
741762
WCHAR* application_path = NULL, *application = NULL, *arguments = NULL,
742-
*env = NULL, *cwd = NULL;
763+
*env = NULL, *cwd = NULL;
743764
STARTUPINFOW startup;
744765
PROCESS_INFORMATION info;
745766
DWORD process_flags;
@@ -774,6 +795,12 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
774795
if (err.code != UV_OK)
775796
goto done;
776797

798+
if (options.env) {
799+
err = make_program_env(options.env, &env);
800+
if (err.code != UV_OK)
801+
goto done;
802+
}
803+
777804
if (options.cwd) {
778805
/* Explicit cwd */
779806
err = uv_utf8_to_utf16_alloc(options.cwd, &cwd);

0 commit comments

Comments
 (0)