Fix FastCGI segfault error
This commit is contained in:
@ -95,7 +95,7 @@ int fastcgi_init(fastcgi_cnx_t *conn, int mode, unsigned int req_num, const sock
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (connect(conn->socket.socket, (struct sockaddr *) &sock_addr, sizeof(sock_addr)) != 0) {
|
if (connect(conn->socket.socket, (struct sockaddr *) &sock_addr, sizeof(sock_addr)) != 0) {
|
||||||
error("Unable to connect to unix socket of FastCGI socket");
|
error("Unable to connect to FastCGI (unix) socket");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ void fastcgi_handler_func(client_ctx_t *ctx) {
|
|||||||
case 1: return;
|
case 1: return;
|
||||||
case 2: break;
|
case 2: break;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (ctx->fcgi_ctx != NULL) {
|
||||||
fastcgi_close(ctx->fcgi_ctx);
|
fastcgi_close(ctx->fcgi_ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,14 +46,6 @@ static int fastcgi_handler_1(client_ctx_t *ctx, fastcgi_cnx_t **fcgi_cnx) {
|
|||||||
http_uri *uri = &ctx->uri;
|
http_uri *uri = &ctx->uri;
|
||||||
sock *client = &ctx->socket;
|
sock *client = &ctx->socket;
|
||||||
char *err_msg = ctx->err_msg;
|
char *err_msg = ctx->err_msg;
|
||||||
|
|
||||||
fastcgi_cnx_t fcgi_cnx_buf;
|
|
||||||
(*fcgi_cnx) = &fcgi_cnx_buf;
|
|
||||||
sock_init(&(*fcgi_cnx)->socket, 0, 0);
|
|
||||||
(*fcgi_cnx)->req_id = 0;
|
|
||||||
(*fcgi_cnx)->r_addr = ctx->socket.addr;
|
|
||||||
(*fcgi_cnx)->r_host = (ctx->host[0] != 0) ? ctx->host : NULL;
|
|
||||||
|
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
int mode, ret;
|
int mode, ret;
|
||||||
@ -62,21 +54,29 @@ static int fastcgi_handler_1(client_ctx_t *ctx, fastcgi_cnx_t **fcgi_cnx) {
|
|||||||
} else {
|
} else {
|
||||||
res->status = http_get_status(500);
|
res->status = http_get_status(500);
|
||||||
error("Invalid FastCGI extension: %s", uri->filename);
|
error("Invalid FastCGI extension: %s", uri->filename);
|
||||||
return 0;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fastcgi_cnx_t fcgi_cnx_buf;
|
||||||
|
sock_init(&fcgi_cnx_buf.socket, 0, 0);
|
||||||
|
fcgi_cnx_buf.req_id = 0;
|
||||||
|
fcgi_cnx_buf.r_addr = ctx->socket.addr;
|
||||||
|
fcgi_cnx_buf.r_host = (ctx->host[0] != 0) ? ctx->host : NULL;
|
||||||
|
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
stat(uri->filename, &statbuf);
|
stat(uri->filename, &statbuf);
|
||||||
char *last_modified = http_format_date(statbuf.st_mtime, buf, sizeof(buf));
|
char *last_modified = http_format_date(statbuf.st_mtime, buf, sizeof(buf));
|
||||||
http_add_header_field(&res->hdr, "Last-Modified", last_modified);
|
http_add_header_field(&res->hdr, "Last-Modified", last_modified);
|
||||||
|
|
||||||
res->status = http_get_status(200);
|
res->status = http_get_status(200);
|
||||||
if (fastcgi_init(*fcgi_cnx, mode, ctx->req_num, client, req, uri) != 0) {
|
if (fastcgi_init(&fcgi_cnx_buf, mode, ctx->req_num, client, req, uri) != 0) {
|
||||||
|
fastcgi_close_cnx(&fcgi_cnx_buf);
|
||||||
res->status = http_get_status(503);
|
res->status = http_get_status(503);
|
||||||
sprintf(err_msg, "Unable to communicate with FastCGI socket.");
|
sprintf(err_msg, "Unable to communicate with FastCGI socket.");
|
||||||
return 2;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(*fcgi_cnx) = &fcgi_cnx_buf;
|
||||||
fastcgi_handle_connection(ctx, fcgi_cnx);
|
fastcgi_handle_connection(ctx, fcgi_cnx);
|
||||||
|
|
||||||
const char *client_content_length = http_get_header_field(&req->hdr, "Content-Length");
|
const char *client_content_length = http_get_header_field(&req->hdr, "Content-Length");
|
||||||
|
Reference in New Issue
Block a user