From 168c439ee89115c584faa4e36ee6d00d1f5cbfea Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 25 Mar 2023 07:46:47 +0100 Subject: [PATCH] Fix vfork wrapper for macOS --- libs/vfork/exec_wrapper.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libs/vfork/exec_wrapper.c b/libs/vfork/exec_wrapper.c index 0453262b5a..870a1e3bf6 100644 --- a/libs/vfork/exec_wrapper.c +++ b/libs/vfork/exec_wrapper.c @@ -45,7 +45,17 @@ static int close_allv (const int except_fds[]) { return -1; } - for (int fd = 0; fd < (int) rl.rlim_max; fd++) { + int max_fd; + if (rl.rlim_cur >= 4194304) { + /* Impose a sane limit, in case the value is + * RLIM_INFINITY 2^63 -1 + */ + max_fd = 4194304; + } else { + max_fd = (int)rl.rlim_cur; + } + + for (int fd = 0; fd < max_fd; fd++) { if (fd <= 3) { continue; } @@ -82,8 +92,6 @@ int main(int argc, char *argv[]) { pout[0] = atoi(argv[5]); pout[1] = atoi(argv[6]); - int good_fds[3] = { pok[1], pout[1], -1 }; - int stderr_mode = atoi(argv[7]); int nicelevel = atoi(argv[8]); @@ -137,6 +145,7 @@ int main(int argc, char *argv[]) { signal(SIGPIPE, SIG_DFL); #endif + int good_fds[2] = { pok[1], -1 }; if (0 == close_allv (good_fds)) { /* all systems go */ execve(argv[9], &argv[9], envp);