Explorar el Código

[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 hace 8 años
padre
commit
2c197517f2
Se han modificado 1 ficheros con 2 adiciones y 0 borrados
  1. 2
    0
      src/core/random.c

+ 2
- 0
src/core/random.c Ver fichero

18
  */
18
  */
19
 void srandom ( unsigned int seed ) {
19
 void srandom ( unsigned int seed ) {
20
 	rnd_seed = seed;
20
 	rnd_seed = seed;
21
+	if ( ! rnd_seed )
22
+		rnd_seed = 4; /* Chosen by fair dice roll */
21
 }
23
 }
22
 
24
 
23
 /**
25
 /**

Loading…
Cancelar
Guardar