diff options
author | Rich Felker <dalias@aerifal.cx> | 2012-06-20 14:32:48 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2012-06-20 14:32:48 -0400 |
commit | f305467aad4659e92fff84be6c89d4767b6f99d4 (patch) | |
tree | ded2078e2d9ca11091774e41cc71bd3c2df45a0b /src | |
parent | b3d7d062af63d833b9a984770320534719252b61 (diff) | |
download | musl-f305467aad4659e92fff84be6c89d4767b6f99d4.tar.gz musl-f305467aad4659e92fff84be6c89d4767b6f99d4.tar.xz musl-f305467aad4659e92fff84be6c89d4767b6f99d4.zip |
popen: handle issues with fd0/1 being closed
also check for failure of dup2 and abort the child rather than reading/writing the wrong file.
Diffstat (limited to 'src')
-rw-r--r-- | src/stdio/popen.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/stdio/popen.c b/src/stdio/popen.c index 1d33e9d6..50765daa 100644 --- a/src/stdio/popen.c +++ b/src/stdio/popen.c @@ -31,9 +31,9 @@ FILE *popen(const char *cmd, const char *mode) close(p[1]); return NULL; case 0: - dup2(p[1-op], 1-op); - close(p[0]); - close(p[1]); + if (dup2(p[1-op], 1-op) < 0) _exit(127); + if (p[0] != 1-op) close(p[0]); + if (p[1] != 1-op) close(p[1]); execl("/bin/sh", "sh", "-c", cmd, (char *)0); _exit(127); } |