Close all the file descriptors in the range [3 ..
sysconf(_SC_OPEN_MAX)-1] before executing a filter program to avoid
leaking file descriptors into subprocesses.
Bug: https://github.com/libarchive/libarchive/issues/2520
int stdin_pipe[2], stdout_pipe[2], tmp;
#if !defined(POSIX_SPAWN_CLOEXEC_DEFAULT) && \
- (HAVE_FORK || HAVE_VFORK) && (HAVE_CLOSEFROM || HAVE_CLOSE_RANGE)
+ (HAVE_FORK || HAVE_VFORK) && \
+ (HAVE_CLOSEFROM || HAVE_CLOSE_RANGE || defined(_SC_OPEN_MAX))
#undef HAVE_POSIX_SPAWNP
#endif
closefrom(3);
#elif HAVE_CLOSE_RANGE
close_range(3, ~0U, 0);
+#elif defined(_SC_OPEN_MAX)
+ for (int i = sysconf(_SC_OPEN_MAX); i > 3;)
+ close(--i);
#endif
execvp(cmdline->path, cmdline->argv);