diff options
author | Ron Yorston <rmy@pobox.com> | 2021-10-28 14:24:24 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-10-28 14:24:24 +0100 |
commit | 5b48ca53be57bc907ed8dd00635914556b4472e4 (patch) | |
tree | 98b7ad2143efaa39608227eb470b8903e19d9b3d | |
parent | d239d2d5273e1620a6146d8f5076f6532e3569b1 (diff) | |
download | busybox-w32-5b48ca53be57bc907ed8dd00635914556b4472e4.tar.gz busybox-w32-5b48ca53be57bc907ed8dd00635914556b4472e4.tar.bz2 busybox-w32-5b48ca53be57bc907ed8dd00635914556b4472e4.zip |
win32: pass NULL to spawnve, not environ
Building busybox-w32 for use with UCRT results in mysterious
failures. (GitHub issue #234)
These are somehow related to the environment values passed to
spawnve. In several places the global environ pointer was being
passed to spawnve so the child would inherit its environment from
the parent. This can also be achieved by passing a NULL pointer.
This prevents the failures in at least some cases and also makes
the binary smaller.
-rw-r--r-- | shell/ash.c | 2 | ||||
-rw-r--r-- | win32/process.c | 8 |
2 files changed, 5 insertions, 5 deletions
diff --git a/shell/ash.c b/shell/ash.c index 3e741d7d2..ad1e5ba7e 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -16016,7 +16016,7 @@ spawn_forkshell(struct forkshell *fs, struct job *jp, union node *n, int mode) | |||
16016 | new->nprocs = jp == NULL ? 0 : jp->nprocs; | 16016 | new->nprocs = jp == NULL ? 0 : jp->nprocs; |
16017 | sprintf(buf, "%p", new->hMapFile); | 16017 | sprintf(buf, "%p", new->hMapFile); |
16018 | argv[2] = buf; | 16018 | argv[2] = buf; |
16019 | ret = spawnve(P_NOWAIT, bb_busybox_exec_path, (char *const *)argv, environ); | 16019 | ret = spawnve(P_NOWAIT, bb_busybox_exec_path, (char *const *)argv, NULL); |
16020 | CloseHandle(new->hMapFile); | 16020 | CloseHandle(new->hMapFile); |
16021 | UnmapViewOfFile(new); | 16021 | UnmapViewOfFile(new); |
16022 | if (ret == -1) { | 16022 | if (ret == -1) { |
diff --git a/win32/process.c b/win32/process.c index 1b344f747..d5f386a1b 100644 --- a/win32/process.c +++ b/win32/process.c | |||
@@ -378,7 +378,7 @@ mingw_spawn_pid(int mode, char **argv) | |||
378 | { | 378 | { |
379 | intptr_t ret; | 379 | intptr_t ret; |
380 | 380 | ||
381 | ret = mingw_spawn_1(mode, argv[0], (char *const *)argv, environ); | 381 | ret = mingw_spawn_1(mode, argv[0], (char *const *)argv, NULL); |
382 | 382 | ||
383 | return ret == -1 ? (pid_t)-1 : (pid_t)GetProcessId((HANDLE)ret); | 383 | return ret == -1 ? (pid_t)-1 : (pid_t)GetProcessId((HANDLE)ret); |
384 | } | 384 | } |
@@ -398,13 +398,13 @@ mingw_spawn_detach(char **argv) | |||
398 | intptr_t FAST_FUNC | 398 | intptr_t FAST_FUNC |
399 | mingw_spawn_proc(const char **argv) | 399 | mingw_spawn_proc(const char **argv) |
400 | { | 400 | { |
401 | return mingw_spawn_1(P_NOWAIT, argv[0], (char *const *)argv, environ); | 401 | return mingw_spawn_1(P_NOWAIT, argv[0], (char *const *)argv, NULL); |
402 | } | 402 | } |
403 | 403 | ||
404 | int | 404 | int |
405 | mingw_execvp(const char *cmd, char *const *argv) | 405 | mingw_execvp(const char *cmd, char *const *argv) |
406 | { | 406 | { |
407 | int ret = (int)mingw_spawn_1(P_WAIT, cmd, argv, environ); | 407 | int ret = (int)mingw_spawn_1(P_WAIT, cmd, argv, NULL); |
408 | if (ret != -1 || errno == 0) | 408 | if (ret != -1 || errno == 0) |
409 | exit(ret); | 409 | exit(ret); |
410 | return ret; | 410 | return ret; |
@@ -422,7 +422,7 @@ mingw_execve(const char *cmd, char *const *argv, char *const *envp) | |||
422 | int | 422 | int |
423 | mingw_execv(const char *cmd, char *const *argv) | 423 | mingw_execv(const char *cmd, char *const *argv) |
424 | { | 424 | { |
425 | return mingw_execve(cmd, argv, environ); | 425 | return mingw_execve(cmd, argv, NULL); |
426 | } | 426 | } |
427 | 427 | ||
428 | static inline long long filetime_to_ticks(const FILETIME *ft) | 428 | static inline long long filetime_to_ticks(const FILETIME *ft) |