]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Ensure the first random number is non-zero when fuzzing
authorTony Finch <fanf@isc.org>
Wed, 21 Sep 2022 11:21:32 +0000 (12:21 +0100)
committerTony Finch <fanf@isc.org>
Wed, 21 Sep 2022 11:47:26 +0000 (12:47 +0100)
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

index 8f804360dbd953846317b1d5ed8aa3403b83cb1b..e37366d8cd06f8a0897790cbdcba5e1a460bc572 100644 (file)
@@ -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