diff options
author | 2012-03-21 12:36:49 +0000 | |
---|---|---|
committer | 2012-03-21 12:36:49 +0000 | |
commit | ec4c3b823609443b8e8c271a9d26285c8d862e1d (patch) | |
tree | 505b836cd1afe96c5ef308e9497f0a6edc6cb61b /lib/libc/stdlib/random.c | |
parent | Switch ld.so's _dl_opendir functions to use a locally defined (diff) | |
download | wireguard-openbsd-ec4c3b823609443b8e8c271a9d26285c8d862e1d.tar.xz wireguard-openbsd-ec4c3b823609443b8e8c271a9d26285c8d862e1d.zip |
Fix a bug where random() always returns 0 when srandom() is seeded
with 0. Use 1 and not 0 as the first element of the state array,
similar to what glibc does. OK nicm@
Diffstat (limited to 'lib/libc/stdlib/random.c')
-rw-r--r-- | lib/libc/stdlib/random.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/libc/stdlib/random.c b/lib/libc/stdlib/random.c index 48e892042ba..5a9a7c33136 100644 --- a/lib/libc/stdlib/random.c +++ b/lib/libc/stdlib/random.c @@ -1,4 +1,4 @@ -/* $OpenBSD: random.c,v 1.15 2005/11/30 07:51:02 otto Exp $ */ +/* $OpenBSD: random.c,v 1.16 2012/03/21 12:36:49 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. * All rights reserved. @@ -196,7 +196,8 @@ srandom(unsigned int x) if (rand_type == TYPE_0) state[0] = x; else { - state[0] = x; + /* A seed of 0 would result in state[] always being zero. */ + state[0] = x ? x : 1; for (i = 1; i < rand_deg; i++) { /* * Implement the following, without overflowing 31 bits: |