BUG/MEDIUM: peers: fix decoding of multi-byte length in stick-table messages
authorWilly Tarreau <w@1wt.eu>
Fri, 13 Nov 2020 13:10:20 +0000 (14:10 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 13 Nov 2020 15:36:19 +0000 (16:36 +0100)
commitd4913917c6e471b1d18c0574711768b3b47ea151
tree48b70eba5f4e560d5e580596acbdd125398f18f7
parent9650ee94b3cc5bc2e6c2a7cf67ef66c0273c1404
BUG/MEDIUM: peers: fix decoding of multi-byte length in stick-table messages

There is a bug in peer_recv_msg() due to an incorrect cast when trying
to decode the varint length of a stick-table message, causing lengths
comprised between 128 and 255 to consume one extra byte, ending in
protocol errors.  The root cause of this is that peer_recv_msg() tries
hard to reimplement all the parsing and control that is already done in
intdecode() just to measure the length before calling it. And it got it
wrong.

Let's just get rid of this unneeded code duplication and solely rely on
intdecode() instead. The bug was introduced in 2.0 as part of a cleanup
pass on this code with commit 95203f218 ("MINOR: peers: Move high level
receive code to reduce the size of I/O handler."), so this patch must
be backported to 2.0.

Thanks to Yves Lafon for reporting the problem.

(cherry picked from commit 1dfd4f106f15bc4e6e992f8babbc863c12975b5a)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
src/peers.c