BUG/MEDIUM: stconn: Fix comparison sign in sc_need_room()
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 4 Aug 2023 08:36:06 +0000 (10:36 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 6 Oct 2023 13:34:31 +0000 (15:34 +0200)
commita633338b55b453752a88134299cd93d9a01997d0
tree89ba9cfebc0e2670570bdd45fad43f0048fea92d
parent31e8a003a516ba23f497a75b1f13400fbe35d6e1
BUG/MEDIUM: stconn: Fix comparison sign in sc_need_room()

sc_need_room() function may be called with a negative value. In this case,
the intent is to be notified if any space was made in the channel buffer. In
the function, we get the min between the requested room and the maximum
possible room in the buffer, considering it may be an HTX buffer.

However this max value is unsigned and leads to an unsigned comparison,
casting the negative value to an unsigned value. Of course, in this case,
this always leads to the wrong result. This bug seems to have no effect but
it is hard to be sure.

To fix the issue, we take care to respect the requested room sign by casting
the max value to a signed integer.

This patch must be backported to 2.8.
include/haproxy/stconn.h