projects
/
oweals
/
musl.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
b3d7d06
)
popen: handle issues with fd0/1 being closed
author
Rich Felker
<dalias@aerifal.cx>
Wed, 20 Jun 2012 18:32:48 +0000
(14:32 -0400)
committer
Rich Felker
<dalias@aerifal.cx>
Wed, 20 Jun 2012 18:32:48 +0000
(14:32 -0400)
also check for failure of dup2 and abort the child rather than
reading/writing the wrong file.
src/stdio/popen.c
patch
|
blob
|
history
diff --git
a/src/stdio/popen.c
b/src/stdio/popen.c
index 1d33e9d692fae195b41af7ca8179e972c155c710..50765daa3f2d899848e69fc78f66f309a96c8de9 100644
(file)
--- 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);
}