]> git.kaiwu.me - haproxy.git/commit
BUG/MINOR: peers: reject over-long varints in intdecode()
authorFrederic Lecaille <flecaille@haproxy.com>
Fri, 23 Oct 2026 08:32:21 +0000 (10:32 +0200)
committerFrederic Lecaille <flecaille@haproxy.com>
Mon, 26 Oct 2026 10:39:41 +0000 (11:39 +0100)
commit690801bed3fb1cc41877b830f0a8d5d762d961f9
treef0ca375a847c1ef3af2083bb43111d2c632180c1
parent0ffabaf2c3aba24695b19eee102b448831d9f322
BUG/MINOR: peers: reject over-long varints in intdecode()

intdecode() shifts continuation bytes by 7 more bits for as long as they
have their stop bit set, without any upper bound on the shift count. A
64-bit value never needs more than 10 bytes, i.e. a shift of 60, but a
malformed message can carry a varint whose 10th continuation byte would
be shifted by 67. Shifting a 64-bit value by 64 or more is undefined
behavior, reported by UBSan, and yields a garbage value.

Check the shift count along with the end of buffer before consuming the
byte, so that such an encoding is rejected. Values up to 2^64-1, which is
encoded on exactly 10 bytes, are still accepted.

Only a buggy or malicious peer sending a malformed varint can reach this:
a compliant peer never emits more than 10 bytes, and peer sessions are
expected to run on trusted networks. The decoded value is later
range-checked against the message bounds, so no memory safety issue is
known; this is UB hardening.

This is long-standing and can be backported to all stable versions.
src/peers.c