2 Commits

Author SHA1 Message Date
31cd2e7e73 Fix FastCGI segfault error 2023-07-01 20:21:21 +02:00
bd8e71e83d Rename fcgi_cnx to fcgi_ctx in client struct 2023-07-01 20:13:51 +02:00
5 changed files with 26 additions and 26 deletions

View File

@@ -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) {
error("Unable to connect to unix socket of FastCGI socket");
error("Unable to connect to FastCGI (unix) socket");
return -1;
}

View File

@@ -43,7 +43,7 @@ int fastcgi_handle_connection(client_ctx_t *ctx, fastcgi_cnx_t **cnx) {
a->closed = 0;
a->client = ctx;
memcpy(&a->cnx, *cnx, sizeof(fastcgi_cnx_t));
ctx->fcgi_cnx = a;
ctx->fcgi_ctx = a;
fastcgi_handle_frame(a);
*cnx = &a->cnx;
@@ -66,7 +66,7 @@ void fastcgi_close(fastcgi_ctx_t *ctx) {
debug("Closing FastCGI connection");
fastcgi_close_cnx(&ctx->cnx);
ctx->client->fcgi_cnx = NULL;
ctx->client->fcgi_ctx = NULL;
free(ctx);
errno = 0;
}

View File

@@ -31,8 +31,8 @@ void fastcgi_handler_func(client_ctx_t *ctx) {
case 1: return;
case 2: break;
}
} else {
fastcgi_close(ctx->fcgi_cnx);
} else if (ctx->fcgi_ctx != NULL) {
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;
sock *client = &ctx->socket;
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];
int mode, ret;
@@ -62,21 +54,29 @@ static int fastcgi_handler_1(client_ctx_t *ctx, fastcgi_cnx_t **fcgi_cnx) {
} else {
res->status = http_get_status(500);
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;
stat(uri->filename, &statbuf);
char *last_modified = http_format_date(statbuf.st_mtime, buf, sizeof(buf));
http_add_header_field(&res->hdr, "Last-Modified", last_modified);
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);
sprintf(err_msg, "Unable to communicate with FastCGI socket.");
return 2;
return 3;
}
(*fcgi_cnx) = &fcgi_cnx_buf;
fastcgi_handle_connection(ctx, fcgi_cnx);
const char *client_content_length = http_get_header_field(&req->hdr, "Content-Length");
@@ -148,9 +148,9 @@ static int fastcgi_handler_1(client_ctx_t *ctx, fastcgi_cnx_t **fcgi_cnx) {
}
static void fastcgi_next_cb(chunk_ctx_t *ctx) {
if(ctx->client->fcgi_cnx) {
fastcgi_close(ctx->client->fcgi_cnx);
ctx->client->fcgi_cnx = NULL;
if(ctx->client->fcgi_ctx) {
fastcgi_close(ctx->client->fcgi_ctx);
ctx->client->fcgi_ctx = NULL;
}
fastcgi_handle(ctx->client);
@@ -163,9 +163,9 @@ static void fastcgi_error_cb(chunk_ctx_t *ctx) {
logger_set_prefix("[%s%*s%s]%s", BLD_STR, ADDRSTRLEN, ctx->client->req_host, CLR_STR, ctx->client->log_prefix);
warning("Closing connection due to FastCGI error");
if(ctx->client->fcgi_cnx) {
fastcgi_close(ctx->client->fcgi_cnx);
ctx->client->fcgi_cnx = NULL;
if(ctx->client->fcgi_ctx) {
fastcgi_close(ctx->client->fcgi_ctx);
ctx->client->fcgi_ctx = NULL;
}
tcp_close(ctx->client);
@@ -181,8 +181,8 @@ static int fastcgi_handler_2(client_ctx_t *ctx, fastcgi_cnx_t *fcgi_cnx) {
return 1;
} else {
fastcgi_send(fcgi_cnx, &ctx->socket);
fastcgi_close(ctx->fcgi_cnx);
ctx->fcgi_cnx = NULL;
fastcgi_close(ctx->fcgi_ctx);
ctx->fcgi_ctx = NULL;
fastcgi_handle(ctx);
return 2;
}

View File

@@ -36,7 +36,7 @@ typedef struct {
long content_length;
char *msg_buf, *msg_buf_ptr, msg_content[1024];
proxy_ctx_t *proxy;
void *fcgi_cnx;
void *fcgi_ctx;
} client_ctx_t;
typedef struct {

View File

@@ -49,7 +49,7 @@ static void init_ctx(client_ctx_t *ctx) {
ctx->proxy = NULL;
ctx->use_fastcgi = 0;
ctx->chunks_transferred = 0;
ctx->fcgi_cnx = NULL;
ctx->fcgi_ctx = NULL;
ctx->use_proxy = 0;
ctx->ws_close = 0;
ctx->proxy = NULL;