From: Christopher Faulet Date: Thu, 3 Dec 2026 09:52:22 +0000 (+0100) Subject: BUG/MINOR: mux-fcgi: don't send anything after the end of the request X-Git-Url: https://git.kaiwu.me/web/http/static/%7B@url%7D?a=commitdiff_plain;h=b9cd0393f2cf352321afe5be1c49592f0a5c3ffb;p=haproxy.git BUG/MINOR: mux-fcgi: don't send anything after the end of the request Once the empty STDIN record marking the end of the request was sent, the stream state was unchanged and fcgi_snd_buf() kept processing the HTX blocks. So a second EOM flag, on a NOOP or an EOT block, led to a second empty STDIN record. And DATA blocks were sent in STDIN records after the end of the request. Both are protocol violations for the FastCGI application. It should not happen with a valid HTX message, but it is safer to properly handle this case. Now, the processing loop stops once the empty STDIN record was sent and the remaining data are drained, like it is done after a close. This patch must be backported to 3.5. --- diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c index 5d8c8d90f..4c25ea106 100644 --- a/src/mux_fcgi.c +++ b/src/mux_fcgi.c @@ -4343,7 +4343,10 @@ static size_t fcgi_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, if (!(fstrm->flags & FCGI_SF_OUTGOING_DATA) && count) fstrm->flags |= FCGI_SF_OUTGOING_DATA; - while (fstrm->state < FCGI_SS_HLOC && !(fstrm->flags & FCGI_SF_BLK_ANY) && + /* Nothing more can be sent once the empty STDIN record, marking the end + * of the request, was sent. Remaining data, if any, are drained below. + */ + while (fstrm->state < FCGI_SS_HLOC && !(fstrm->flags & (FCGI_SF_BLK_ANY|FCGI_SF_ES_SENT)) && count && !htx_is_empty(htx)) { blk = ASSUME_NONNULL(htx_get_head_blk(htx)); bsize = htx_get_blksz(blk); @@ -4412,11 +4415,12 @@ static size_t fcgi_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, } done: - if (fstrm->state >= FCGI_SS_HLOC) { + if (fstrm->state >= FCGI_SS_HLOC || (fstrm->flags & FCGI_SF_ES_SENT)) { struct htx_ret htxret; - /* trim any possibly pending data after we close (extra CR-LF, - * unprocessed trailers, abnormal extra data, ...) + /* trim any possibly pending data after we close or after the + * end of the request (extra CR-LF, unprocessed trailers, + * abnormal extra data, a second EOM...) */ htxret = htx_drain(htx, count); total += htxret.ret;