mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-26 03:12:16 -04:00
chg: dev: Fix assertion failure from arc4random_uniform with invalid limit
When the arc4random_uniform() is called on NetBSD with upper_bound that makes no sense statistically (0 or 1), the call crashes the calling program. Fix this by returning 0 when upper bound is < 2 as does Linux, FreeBSD and NetBSD. (Hint: System CSPRNG should never crash.) Closes #5596 Merge branch '5596-fix-isc_random_uniform-on-NetBSD' into 'main' See merge request isc-projects/bind9!11147
This commit is contained in:
commit
08ccc8bea8
1 changed files with 4 additions and 3 deletions
|
|
@ -25,9 +25,10 @@
|
|||
*/
|
||||
|
||||
#if HAVE_ARC4RANDOM && !defined(__linux__)
|
||||
#define isc_random32() arc4random()
|
||||
#define isc_random_buf(buf, buflen) arc4random_buf(buf, buflen)
|
||||
#define isc_random_uniform(upper_bound) arc4random_uniform(upper_bound)
|
||||
#define isc_random32() arc4random()
|
||||
#define isc_random_buf(buf, buflen) arc4random_buf(buf, buflen)
|
||||
#define isc_random_uniform(upper_bound) \
|
||||
((upper_bound) < 2 ? 0 : arc4random_uniform(upper_bound))
|
||||
#else /* HAVE_ARC4RANDOM && !defined(__linux__) */
|
||||
uint32_t
|
||||
isc_random32(void);
|
||||
|
|
|
|||
Loading…
Reference in a new issue