Bläddra i källkod

[libc] Always use a non-zero seed for the (non-crypto) RNG

The non-cryptographic RNG implemented by random() has the property
that a seed value of zero will result in a generated sequence of
all-zero values.  This situation can arise if currticks() returns zero
at start of day.

Work around this problem by falling back to a fixed non-zero seed if
necessary.

This has no effect on the separate DRBG used by cryptographic code.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 år sedan
förälder
incheckning
2c197517f2
1 ändrade filer med 2 tillägg och 0 borttagningar
  1. 2
    0
      src/core/random.c

+ 2
- 0
src/core/random.c Visa fil

@@ -18,6 +18,8 @@ static int32_t rnd_seed = 0;
18 18
  */
19 19
 void srandom ( unsigned int seed ) {
20 20
 	rnd_seed = seed;
21
+	if ( ! rnd_seed )
22
+		rnd_seed = 4; /* Chosen by fair dice roll */
21 23
 }
22 24
 
23 25
 /**

Laddar…
Avbryt
Spara