GH-1076: Fix bro_srandom() to replace 0 seeds with 1

The bro_prng() implementation cannot generate 0 as a result since it
causes every subsequent number from the PRNG to also be 0, so use the
number 1 instead of 0.
This commit is contained in:
Jon Siwek 2020-07-22 00:07:34 -07:00
parent 0f4eb9af02
commit 887b53b7f3
3 changed files with 11 additions and 2 deletions

View file

@ -1072,7 +1072,7 @@ static unsigned int first_seed = 0;
static void bro_srandom(unsigned int seed, bool deterministic)
{
bro_rand_state = seed;
bro_rand_state = seed == 0 ? 1 : seed;
bro_rand_determistic = deterministic;
srandom(seed);
@ -1081,7 +1081,7 @@ static void bro_srandom(unsigned int seed, bool deterministic)
void bro_srandom(unsigned int seed)
{
if ( bro_rand_determistic )
bro_rand_state = seed;
bro_rand_state = seed == 0 ? 1 : seed;
else
srandom(seed);
}