1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-21 23:38:49 -05:00

alpm_run_chroot: always connect parent2child pipe

Commit e374e6829c closed stdin before
running scripts/hooks.  This left the exec'd process with no file
descriptor 0.  If the process subsequently opened a file it would be
assigned fd 0, and could potentially be confused for stdin.  Connecting
and immediately closing the parent2child pipe ensures that the child has
an fd 0 and that it is empty.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Andrew Gregory 2016-02-21 21:46:38 -05:00 committed by Allan McRae
parent ce1f453b74
commit 1d6583a58d

View File

@ -586,7 +586,7 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[],
goto cleanup; goto cleanup;
} }
if(stdin_cb && pipe(parent2child_pipefd) == -1) { if(pipe(parent2child_pipefd) == -1) {
_alpm_log(handle, ALPM_LOG_ERROR, _("could not create pipe (%s)\n"), strerror(errno)); _alpm_log(handle, ALPM_LOG_ERROR, _("could not create pipe (%s)\n"), strerror(errno));
retval = 1; retval = 1;
goto cleanup; goto cleanup;
@ -607,11 +607,9 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[],
close(2); close(2);
while(dup2(child2parent_pipefd[1], 1) == -1 && errno == EINTR); while(dup2(child2parent_pipefd[1], 1) == -1 && errno == EINTR);
while(dup2(child2parent_pipefd[1], 2) == -1 && errno == EINTR); while(dup2(child2parent_pipefd[1], 2) == -1 && errno == EINTR);
if(stdin_cb) { while(dup2(parent2child_pipefd[0], 0) == -1 && errno == EINTR);
while(dup2(parent2child_pipefd[0], 0) == -1 && errno == EINTR); close(parent2child_pipefd[0]);
close(parent2child_pipefd[0]); close(parent2child_pipefd[1]);
close(parent2child_pipefd[1]);
}
close(child2parent_pipefd[0]); close(child2parent_pipefd[0]);
close(child2parent_pipefd[1]); close(child2parent_pipefd[1]);
if(cwdfd >= 0) { if(cwdfd >= 0) {
@ -646,15 +644,16 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[],
child2parent->events = POLLIN; child2parent->events = POLLIN;
fcntl(child2parent->fd, F_SETFL, O_NONBLOCK); fcntl(child2parent->fd, F_SETFL, O_NONBLOCK);
close(child2parent_pipefd[1]); close(child2parent_pipefd[1]);
close(parent2child_pipefd[0]);
if(stdin_cb) { if(stdin_cb) {
parent2child->fd = parent2child_pipefd[1]; parent2child->fd = parent2child_pipefd[1];
parent2child->events = POLLOUT; parent2child->events = POLLOUT;
fcntl(parent2child->fd, F_SETFL, O_NONBLOCK); fcntl(parent2child->fd, F_SETFL, O_NONBLOCK);
close(parent2child_pipefd[0]);
} else { } else {
parent2child->fd = -1; parent2child->fd = -1;
parent2child->events = 0; parent2child->events = 0;
close(parent2child_pipefd[1]);
} }
#define STOP_POLLING(p) do { close(p->fd); p->fd = -1; } while(0) #define STOP_POLLING(p) do { close(p->fd); p->fd = -1; } while(0)