diff options
author | 2000-04-04 13:38:24 +0000 | |
---|---|---|
committer | 2000-04-04 13:38:24 +0000 | |
commit | 13446e16bbb0d8573ded60dbd79a5de717773aef (patch) | |
tree | b56611125615eaf078189922a566acc8c1a63127 /lib/libc/stdlib/random.c | |
parent | remove accidentally comitted files (diff) | |
download | wireguard-openbsd-13446e16bbb0d8573ded60dbd79a5de717773aef.tar.xz wireguard-openbsd-13446e16bbb0d8573ded60dbd79a5de717773aef.zip |
Fix an fd leak if the read from /dev/arandom fails. Pointed out by
Markus Friedl.
Diffstat (limited to 'lib/libc/stdlib/random.c')
-rw-r--r-- | lib/libc/stdlib/random.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/libc/stdlib/random.c b/lib/libc/stdlib/random.c index 7c6e5f7eb92..2b97c5a54a2 100644 --- a/lib/libc/stdlib/random.c +++ b/lib/libc/stdlib/random.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: random.c,v 1.7 2000/04/03 23:23:48 millert Exp $"; +static char *rcsid = "$OpenBSD: random.c,v 1.8 2000/04/04 13:38:24 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -245,10 +245,8 @@ srandomdev() else len = rand_deg * sizeof(state[0]); - if ((fd = open("/dev/arandom", O_RDONLY, 0)) != -1 && - read(fd, (void *) state, len) == (ssize_t) len) { - close(fd); - } else { + if ((fd = open("/dev/arandom", O_RDONLY, 0)) == -1 || + read(fd, (void *) state, len) != (ssize_t) len) { struct timeval tv; u_int junk; @@ -257,6 +255,8 @@ srandomdev() srandom(getpid() ^ tv.tv_sec ^ tv.tv_usec ^ junk); return; } + if (fd != -1) + close(fd); if (rand_type != TYPE_0) { fptr = &state[rand_sep]; |