提交 f305467a 编写于 作者: R Rich Felker

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.
上级 b3d7d062
......@@ -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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册