]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: mux-fcgi: don't send anything after the end of the request
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 3 Dec 2026 09:52:22 +0000 (10:52 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 3 Dec 2026 12:41:06 +0000 (13:41 +0100)
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.

src/mux_fcgi.c

index 5d8c8d90f42bc5806ad78cfa9731916b826e9bb5..4c25ea106f9cc75748f3324cf5eba911f2992ac7 100644 (file)
@@ -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;