Commit d883b0f0 authored by Sergey Lyubka's avatar Sergey Lyubka

Prevent possible assert fail on windows in handle_cgi_request()

parent 0b942aaa
......@@ -3110,7 +3110,15 @@ static void handle_cgi_request(struct mg_connection *conn, const char *prog) {
send_http_error(conn, 500, http_500_error,
"Cannot spawn CGI process [%s]: %s", prog, strerror(ERRNO));
goto done;
} else if ((in = fdopen(fd_stdin[1], "wb")) == NULL ||
}
// spawn_process() must close those!
// If we don't mark them as closed, close() attempt before
// return from this function throws an exception on Windows.
// Windows does not like when closed descriptor is closed again.
fd_stdin[0] = fd_stdout[1] = -1;
if ((in = fdopen(fd_stdin[1], "wb")) == NULL ||
(out = fdopen(fd_stdout[0], "rb")) == NULL) {
send_http_error(conn, 500, http_500_error,
"fopen: %s", strerror(ERRNO));
......@@ -3120,12 +3128,6 @@ static void handle_cgi_request(struct mg_connection *conn, const char *prog) {
setbuf(in, NULL);
setbuf(out, NULL);
// spawn_process() must close those!
// If we don't mark them as closed, close() attempt before
// return from this function throws an exception on Windows.
// Windows does not like when closed descriptor is closed again.
fd_stdin[0] = fd_stdout[1] = -1;
// Send POST data to the CGI process if needed
if (!strcmp(conn->request_info.request_method, "POST") &&
!forward_body_data(conn, in, INVALID_SOCKET, NULL)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment