BUG/MAJOR: buf: fix varint API post- vs pre- increment
authorWilly Tarreau <w@1wt.eu>
Thu, 21 Oct 2021 13:05:34 +0000 (15:05 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 3 Nov 2021 10:49:56 +0000 (11:49 +0100)
commit4c71bbc3649c9c08b33f8f593fefa31d2b61ada9
tree99806e1f3b2b1307b8e5bf8046efc4985275b45e
parent6ba9eaecb166db42efc2b555fdc46c35b39ec14d
BUG/MAJOR: buf: fix varint API post- vs pre- increment

A bogus test in b_get_varint(), b_put_varint(), b_peek_varint() shifts
the end of the buffer by one byte. Since the bug is the same in the read
and write functions, the buffer contents remain compatible, which explains
why this bug was not detected earlier. But if the buffer ends on an
aligned address or page, it can result in a one-byte overflow which will
typically cause a crash or an inconsistent behavior.

This API is only used by rings (e.g. for traces and boot messages) and
by DNS responses, so the probability to hit it is extremely low, but a
crash on boot was observed.

This must be backported to 2.2.

(cherry picked from commit dd362b7b24ea24d8f3c882dab1a69cf78af7cc90)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit db5bf3d89cc4290aacb15ec348bb2bcdcaa1c201)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
include/haproxy/buf.h