summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormillert <>2000-04-04 14:27:00 +0000
committermillert <>2000-04-04 14:27:00 +0000
commit49942362248a15d0555f7bcddd090271eb1a6fbb (patch)
tree076ce63cbd8f3184e8e68b3f5f27c2ee04e9503f
parentead26851c853278c861706f40bd67ea1e0e88bcb (diff)
downloadopenbsd-49942362248a15d0555f7bcddd090271eb1a6fbb.tar.gz
openbsd-49942362248a15d0555f7bcddd090271eb1a6fbb.tar.bz2
openbsd-49942362248a15d0555f7bcddd090271eb1a6fbb.zip
Fix the leak for real (that's what I get for hacking when i can't sleep).
-rw-r--r--src/lib/libc/stdlib/random.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/lib/libc/stdlib/random.c b/src/lib/libc/stdlib/random.c
index 2b97c5a54a..5ce7c90ee9 100644
--- a/src/lib/libc/stdlib/random.c
+++ b/src/lib/libc/stdlib/random.c
@@ -32,7 +32,7 @@
32 */ 32 */
33 33
34#if defined(LIBC_SCCS) && !defined(lint) 34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: random.c,v 1.8 2000/04/04 13:38:24 millert Exp $"; 35static char *rcsid = "$OpenBSD: random.c,v 1.9 2000/04/04 14:27:00 millert Exp $";
36#endif /* LIBC_SCCS and not lint */ 36#endif /* LIBC_SCCS and not lint */
37 37
38#include <sys/types.h> 38#include <sys/types.h>
@@ -245,18 +245,20 @@ srandomdev()
245 else 245 else
246 len = rand_deg * sizeof(state[0]); 246 len = rand_deg * sizeof(state[0]);
247 247
248 if ((fd = open("/dev/arandom", O_RDONLY, 0)) == -1 || 248 if ((fd = open("/dev/arandom", O_RDONLY, 0)) != -1 &&
249 read(fd, (void *) state, len) != (ssize_t) len) { 249 read(fd, (void *) state, len) == (ssize_t) len) {
250 close(fd);
251 } else {
250 struct timeval tv; 252 struct timeval tv;
251 u_int junk; 253 u_int junk;
252 254
253 /* XXX - this could be better */ 255 /* XXX - this could be better */
254 gettimeofday(&tv, NULL); 256 gettimeofday(&tv, NULL);
255 srandom(getpid() ^ tv.tv_sec ^ tv.tv_usec ^ junk); 257 srandom(getpid() ^ tv.tv_sec ^ tv.tv_usec ^ junk);
258 if (fd != -1)
259 close(fd);
256 return; 260 return;
257 } 261 }
258 if (fd != -1)
259 close(fd);
260 262
261 if (rand_type != TYPE_0) { 263 if (rand_type != TYPE_0) {
262 fptr = &state[rand_sep]; 264 fptr = &state[rand_sep];