summaryrefslogtreecommitdiffstats
path: root/sys/libkern/arc4random.c
diff options
context:
space:
mode:
authordan <dan@FreeBSD.org>1999-11-29 19:23:35 +0000
committerdan <dan@FreeBSD.org>1999-11-29 19:23:35 +0000
commit2caf8b3c1a4dea929715ebd5a7fb4746b9058134 (patch)
treee4a75a4f0240e2af9d6cbe8dd0c8be874e7c7fff /sys/libkern/arc4random.c
parentf7d7085dbeec7f40c137f190df9dc78b149e8700 (diff)
downloadFreeBSD-src-2caf8b3c1a4dea929715ebd5a7fb4746b9058134.zip
FreeBSD-src-2caf8b3c1a4dea929715ebd5a7fb4746b9058134.tar.gz
In the extremely miniscule chance that read_random returns <= 0, don't try
and use that return code as a modulus (panics are bad, mmmkay?)
Diffstat (limited to 'sys/libkern/arc4random.c')
-rw-r--r--sys/libkern/arc4random.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/sys/libkern/arc4random.c b/sys/libkern/arc4random.c
index b6d9070..4eefb69 100644
--- a/sys/libkern/arc4random.c
+++ b/sys/libkern/arc4random.c
@@ -41,8 +41,12 @@ arc4_randomstir (void)
int r, n;
r = read_random(key, sizeof(key));
- for (n = r; n < sizeof(key); n++)
- key[n] = key[n % r];
+ /* if r == 0 || -1, just use what was on the stack */
+ if (r > 0)
+ {
+ for (n = r; n < sizeof(key); n++)
+ key[n] = key[n % r];
+ }
for (n = 0; n < 256; n++)
{
OpenPOWER on IntegriCloud