From: Willy Tarreau Date: Mon, 18 Jul 2022 17:09:55 +0000 (+0200) Subject: BUG/MINOR: tools: fix statistical_prng_range()'s output range X-Git-Tag: v2.7-dev3~83 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03f3049df167069f1bf802c18c275524c346513c;p=thirdparty%2Fhaproxy.git BUG/MINOR: tools: fix statistical_prng_range()'s output range This function was added by commit 84ebfabf7 ("MINOR: tools: add statistical_prng_range() to get a random number over a range") but it contains a bug on the range, since mul32hi() covers the whole input range, we must pass it range-1. For now it didn't have any impact, but if used to find an array's index it will cause trouble. This should be backported to 2.4. --- diff --git a/include/haproxy/tools.h b/include/haproxy/tools.h index 90d46a60d1..3059fa847a 100644 --- a/include/haproxy/tools.h +++ b/include/haproxy/tools.h @@ -1063,7 +1063,7 @@ static inline unsigned int statistical_prng() */ static inline uint statistical_prng_range(uint range) { - return mul32hi(statistical_prng(), range); + return mul32hi(statistical_prng(), range ? range - 1 : 0); } /* Update array with the character transition to . If