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)
committerWilly Tarreau <w@1wt.eu>
Wed, 22 Sep 2021 05:24:02 +0000 (07:24 +0200)
commit6f97b4ef3383f59ff3218f73fcd21f94335b2c1b
treed0711aff87c0bd09042f21d01f1e4016f81f1b56
parentc8cac04bd516a5af6fb5a6e967059a90f03c2a99
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.
src/lb_fwlc.c