diff options
author | Omar Polo <op@omarpolo.com> | 2021-07-06 10:48:59 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2021-07-06 10:48:59 +0000 |
commit | ea976e8743ad3b3263faae00d88e40bcf727097d (patch) | |
tree | 108ff4f3b338c55e326af021a24cb16abfbb7cbd | |
parent | ef945cf4157bc8239c6da682a89ba60b11cc0e26 (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.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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]; } |