BUG/MEDIUM: leastconn: fix rare possibility of divide by zero
authorWilly Tarreau <w@1wt.eu>
Wed, 22 Sep 2021 05:15:57 +0000 (07:15 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 8 Oct 2021 15:30:13 +0000 (17:30 +0200)
commit54f9064a3286ab45872640ad19bc84efc719179f
tree8d4c8483fee592565648dab03c59f85e4996065d
parent0993832844cb2203b4d778a443b25607996cd7f1
BUG/MEDIUM: leastconn: fix rare possibility of divide by zero

An optimization was brought in commit 5064ab6a9 ("OPTIM: lb-leastconn:
do not unlink the server if it did not change") to avoid locking the
server just to discover it did not move. However a mistake was made
because the operation involves a divide with a value that is read
outside of its usual lock, which makes it possible to be zero at the
exact moment we watch it if another thread takes the server down under
the lbprm lock, resulting in a divide by zero.

Therefore we must check that the value is not null there.

This must be backported to 2.4.

(cherry picked from commit 6f97b4ef3383f59ff3218f73fcd21f94335b2c1b)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 8031464835df8166666f315515604fe6bc3c5598)
[cf: Above commit was backported to 2.3. Thus this patch should be backported
     too.]
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
src/lb_fwlc.c