summaryrefslogtreecommitdiff
path: root/rpmio/rpmfileutil.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2013-04-12 09:19:35 +0300
committerPanu Matilainen <pmatilai@redhat.com>2013-04-12 09:52:03 +0300
commitae58a02861977d3a71a68bc1851cd0a70ec889f0 (patch)
tree93a273c7bb894cf8b9e8b29299832138cb868613 /rpmio/rpmfileutil.c
parent427477fb3bc811fe8131c1a58f761a547645e610 (diff)
downloadrpm-ae58a02861977d3a71a68bc1851cd0a70ec889f0.tar.gz
Handle fork(), pipe() and dup2() failures in prelink helper launch
- Actually check the return codes from the stuff that matters and deal with failures. Incidentally also eliminates a compiler warning from set-but-not-used variable...
Diffstat (limited to 'rpmio/rpmfileutil.c')
-rw-r--r--rpmio/rpmfileutil.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/rpmio/rpmfileutil.c b/rpmio/rpmfileutil.c
index f411266cd..b68a5c9b1 100644
--- a/rpmio/rpmfileutil.c
+++ b/rpmio/rpmfileutil.c
@@ -105,28 +105,38 @@ static int open_dso(const char * path, pid_t * pidp, rpm_loff_t *fsizep)
if (pidp != NULL && is_prelinked(fdno)) {
int pipes[2];
pid_t pid;
- int xx;
- xx = close(fdno);
+ close(fdno);
pipes[0] = pipes[1] = -1;
- xx = pipe(pipes);
- if (!(pid = fork())) {
+ if (pipe(pipes) < 0)
+ return -1;
+
+ pid = fork();
+ if (pid < 0) {
+ close(pipes[0]);
+ close(pipes[1]);
+ return -1;
+ }
+
+ if (pid == 0) {
ARGV_t av, lib;
+ int dfd;
argvSplit(&av, cmd, " ");
- xx = close(pipes[0]);
- xx = dup2(pipes[1], STDOUT_FILENO);
- xx = close(pipes[1]);
- if ((lib = argvSearch(av, "library", NULL)) != NULL) {
+ close(pipes[0]);
+ dfd = dup2(pipes[1], STDOUT_FILENO);
+ close(pipes[1]);
+ if (dfd >= 0 && (lib = argvSearch(av, "library", NULL)) != NULL) {
*lib = (char *) path;
unsetenv("MALLOC_CHECK_");
- xx = execve(av[0], av+1, environ);
+ execve(av[0], av+1, environ);
}
- _exit(127);
+ _exit(127); /* not normally reached */
+ } else {
+ *pidp = pid;
+ fdno = pipes[0];
+ close(pipes[1]);
}
- *pidp = pid;
- fdno = pipes[0];
- xx = close(pipes[1]);
}
return fdno;