fastcgi: Fix fastcgi_dump()

This commit is contained in:
2026-01-29 18:18:57 +01:00
parent c36ba8d3a5
commit 2675d267b5
2 changed files with 15 additions and 5 deletions

View File

@@ -416,8 +416,17 @@ int fastcgi_header(fastcgi_cnx_t *cnx, http_res *res, char *err_msg) {
return 0; return 0;
} }
int fastcgi_dump(fastcgi_cnx_t *cnx, char *buf, long len) { int fastcgi_dump(fastcgi_cnx_t *cnx, char *buf, const long len) {
return sock_recv_x(&cnx->socket, buf, len, 0) == -1 ? -1 : 0; for (long ret, rcv = 0; rcv < len; rcv += ret) {
if ((ret = sock_recv_chunk_header(&cnx->out)) == -1) {
return -1;
}
const long min = ret > len - rcv ? len - rcv : ret;
if ((ret = sock_recv_x(&cnx->out, buf + rcv, min, 0)) <= 0) {
return -1;
}
}
return 0;
} }
int fastcgi_receive(fastcgi_cnx_t *cnx, sock *client, unsigned long len) { int fastcgi_receive(fastcgi_cnx_t *cnx, sock *client, unsigned long len) {

View File

@@ -145,16 +145,17 @@ static int fastcgi_handler_1(client_ctx_t *ctx, fastcgi_cnx_t **fcgi_cnx) {
content_type != NULL && content_type != NULL &&
strstarts(content_type, "text/html") && strstarts(content_type, "text/html") &&
ctx->content_length != -1 && ctx->content_length != -1 &&
ctx->content_length <= sizeof(ctx->msg_content) - 1) ctx->content_length < sizeof(ctx->msg_content))
{ {
fastcgi_dump(*fcgi_cnx, ctx->msg_content, sizeof(ctx->msg_content)); fastcgi_dump(*fcgi_cnx, ctx->msg_content, ctx->content_length);
ctx->msg_content[ctx->content_length] = 0;
return 1; return 1;
} }
ctx->use_fastcgi = 1; ctx->use_fastcgi = 1;
ctx->content_length = -1; ctx->content_length = -1;
if (http_get_header_field(&res->hdr, "Content-Length") == NULL) { if (content_length_f == NULL) {
http_add_header_field(&res->hdr, "Transfer-Encoding", "chunked"); http_add_header_field(&res->hdr, "Transfer-Encoding", "chunked");
} }