From 4b9af2283012b7f5706d4c42cdfc49a2fcf6bf54 Mon Sep 17 00:00:00 2001 From: Tony Finch Date: Wed, 21 Sep 2022 12:21:32 +0100 Subject: [PATCH] Ensure the first random number is non-zero when fuzzing In fuzzing mode, `isc_random` uses a fixed seed for reproducibility. The particular seed chosen happened to produce zero as its first number, however commit bd251de0 introduced an initialization check in `random_test` that required it to be non-zero. This change adjusts the seed to avoid spurious test failures. Also, remove the temporary variable that was used for initialization because it did not match the type of the thread-local seed array. --- lib/isc/random.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/isc/random.c b/lib/isc/random.c index 8f804360db..e37366d8cd 100644 --- a/lib/isc/random.c +++ b/lib/isc/random.c @@ -90,17 +90,16 @@ next(void) { } void isc__random_initialize(void) { - int useed[4] = { 0, 0, 0, 1 }; #if FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION /* - * Set a constant seed to help in problem reproduction should fuzzing - * find a crash or a hang. The seed array must be non-zero else - * xoshiro128starstar will generate an infinite series of zeroes. + * A fixed seed helps with problem reproduction when fuzzing. It must be + * non-zero else xoshiro128starstar will generate only zeroes, and the + * first result needs to be non-zero as expected by random_test.c */ + seed[0] = 1; #else /* if FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */ - isc_entropy_get(useed, sizeof(useed)); + isc_entropy_get(seed, sizeof(seed)); #endif /* if FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */ - memmove(seed, useed, sizeof(seed)); } uint8_t