]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: mux_quic: fix overflow on avail_streams
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 22 Oct 2026 12:53:59 +0000 (14:53 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 22 Oct 2026 13:09:56 +0000 (15:09 +0200)
Function qcc_fctl_avail_streams() return the number of streams which can
still be opened regarding the limit set by the peer.

The return value is a 32 bits integer, used to store the substraction
result. This may overflow as flow control limit is encoded on 64 bits,
which could result either in blocked transfers, or in spurrious error as
mandatory unistreams could not be opened.

Fix this by using a temporary 64 bits value, and cap it to INT_MAX if
needed. This is sufficient as values larger than INT_MAX is out of a
real case usage.

This must be backported up to 2.8.

src/mux_quic.c

index c67364bed2aafdc3f0e24167cdc7a0361d129a2f..a7925ddb9fcc883eb66b9719c8cf2c82eb33e91e 100644 (file)
@@ -887,16 +887,21 @@ int _qcc_report_glitch(struct qcc *qcc, int inc)
 /* Returns the number of streams which can still be opened until flow-control limit. */
 int qcc_fctl_avail_streams(const struct qcc *qcc, int bidi)
 {
+       uint64_t diff;
+
        if (bidi) {
                const uint64_t next = qcc->next_bidi_l / 4;
                BUG_ON(qcc->rfctl.ms_bidi < next);
-               return qcc->rfctl.ms_bidi - next;
+               diff = qcc->rfctl.ms_bidi - next;
        }
        else {
                const uint64_t next = qcc->next_uni_l / 4;
                BUG_ON(qcc->rfctl.ms_uni < next);
-               return qcc->rfctl.ms_uni - next;
+               diff = qcc->rfctl.ms_uni - next;
        }
+
+       /* cap the value to INT_MAX to avoid overflow */
+       return MIN(diff, INT_MAX);
 }
 
 /* Retrieves the maximum number of bidirectional remote streams that the peer