aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-07-06 10:48:59 +0000
committerOmar Polo <op@omarpolo.com>2021-07-06 10:48:59 +0000
commitea976e8743ad3b3263faae00d88e40bcf727097d (patch)
tree108ff4f3b338c55e326af021a24cb16abfbb7cbd
parentef945cf4157bc8239c6da682a89ba60b11cc0e26 (diff)
don't let CGI scripts inherit our stderr
our stderr could have been sent to the logger process, so it may be invalid. Furthermore, in the future we may want to capture also the stderr of the processes.
-rw-r--r--ex.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/ex.c b/ex.c
index 1868156..8e25bd1 100644
--- a/ex.c
+++ b/ex.c
@@ -128,10 +128,12 @@ static int
launch_cgi(struct iri *iri, struct cgireq *req, struct vhost *vhost,
struct location *loc)
{
- int p[2]; /* read end, write end */
+ int p[2], errp[2]; /* read end, write end */
if (pipe(p) == -1)
return -1;
+ if (pipe(errp) == -1)
+ return -1;
switch (fork()) {
case -1:
@@ -147,6 +149,10 @@ launch_cgi(struct iri *iri, struct cgireq *req, struct vhost *vhost,
if (dup2(p[1], 1) == -1)
goto childerr;
+ close(errp[0]);
+ if (dup2(errp[1], 2) == -1)
+ goto childerr;
+
ex = xasprintf("%s/%s", loc->dir, req->spath);
serialize_iri(iri, iribuf, sizeof(iribuf));
@@ -224,6 +230,7 @@ launch_cgi(struct iri *iri, struct cgireq *req, struct vhost *vhost,
default:
close(p[1]);
+ close(errp[1]);
mark_nonblock(p[0]);
return p[0];
}