module/script: close all unrelated FDs

While most FDs are CLOEXEC, not all are. For example, other script
modules’ re-direction pipes.
This commit is contained in:
Daniel Eklöf 2020-11-02 19:12:26 +01:00
parent 31f6a4a6a0
commit aa34925f54
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -479,6 +479,16 @@ run(struct module *mod)
close(comm_pipe[1]);
comm_pipe[1] = -1;
/* Close *all* other FDs */
for (int i = STDERR_FILENO + 1; i < 65536; i++) {
if (i == exec_pipe[1]) {
/* Needed for error reporting. Automatically closed
* when execvp() succeeds */
continue;
}
close(i);
}
execvp(m->path, argv);
fail: