Browse Source

[mod_cgi] fix crash if initial write to CGI fails

(bug on master branch)
master
Glenn Strauss 2 months ago
parent
commit
fc19558f96
1 changed files with 14 additions and 17 deletions
  1. +14
    -17
      src/mod_cgi.c

+ 14
- 17
src/mod_cgi.c View File

@ -844,27 +844,24 @@ static int cgi_create_env(request_st * const r, plugin_data * const p, handler_c
cgi_pid_add(p, hctx->pid, hctx);
++r->con->srv->cur_fds;
if (0 == r->reqbody_length) {
close(to_cgi_fds[1]);
} else {
/* there is content to send */
if (-1 == fdevent_fcntl_set_nb(to_cgi_fds[1])) {
log_perror(r->conf.errh, __FILE__, __LINE__, "fcntl failed");
close(to_cgi_fds[1]);
cgi_connection_close(hctx);
return -1;
}
if (0 != cgi_write_request(hctx, to_cgi_fds[1])) {
close(to_cgi_fds[1]);
cgi_connection_close(hctx);
return -1;
}
}
else if (0 == fdevent_fcntl_set_nb(to_cgi_fds[1])
&& 0 == cgi_write_request(hctx, to_cgi_fds[1])) {
++r->con->srv->cur_fds;
}
else {
close(to_cgi_fds[1]);
/*(hctx->fd not yet registered with fdevent, so manually
* cleanup here; see fdevent_register() further below)*/
close(hctx->fd);
hctx->fd = -1;
cgi_connection_close(hctx);
return -1;
}
++r->con->srv->cur_fds;
struct fdevents * const ev = hctx->ev;
hctx->fdn = fdevent_register(ev, hctx->fd, cgi_handle_fdevent, hctx);


Loading…
Cancel
Save