From 5b48ca53be57bc907ed8dd00635914556b4472e4 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 28 Oct 2021 14:24:24 +0100 Subject: 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. --- shell/ash.c | 2 +- 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) new->nprocs = jp == NULL ? 0 : jp->nprocs; sprintf(buf, "%p", new->hMapFile); argv[2] = buf; - ret = spawnve(P_NOWAIT, bb_busybox_exec_path, (char *const *)argv, environ); + ret = spawnve(P_NOWAIT, bb_busybox_exec_path, (char *const *)argv, NULL); CloseHandle(new->hMapFile); UnmapViewOfFile(new); 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) { intptr_t ret; - ret = mingw_spawn_1(mode, argv[0], (char *const *)argv, environ); + ret = mingw_spawn_1(mode, argv[0], (char *const *)argv, NULL); return ret == -1 ? (pid_t)-1 : (pid_t)GetProcessId((HANDLE)ret); } @@ -398,13 +398,13 @@ mingw_spawn_detach(char **argv) intptr_t FAST_FUNC mingw_spawn_proc(const char **argv) { - return mingw_spawn_1(P_NOWAIT, argv[0], (char *const *)argv, environ); + return mingw_spawn_1(P_NOWAIT, argv[0], (char *const *)argv, NULL); } int mingw_execvp(const char *cmd, char *const *argv) { - int ret = (int)mingw_spawn_1(P_WAIT, cmd, argv, environ); + int ret = (int)mingw_spawn_1(P_WAIT, cmd, argv, NULL); if (ret != -1 || errno == 0) exit(ret); return ret; @@ -422,7 +422,7 @@ mingw_execve(const char *cmd, char *const *argv, char *const *envp) int mingw_execv(const char *cmd, char *const *argv) { - return mingw_execve(cmd, argv, environ); + return mingw_execve(cmd, argv, NULL); } static inline long long filetime_to_ticks(const FILETIME *ft) -- cgit v1.2.3-55-g6feb