From 8adacc06aa66e6a84849af8699b8eed8fcbd5764 Mon Sep 17 00:00:00 2001 From: Jesse Jones Date: Sat, 17 Nov 2012 16:07:49 -0800 Subject: [PATCH] Some isaac_ssed fixes: 1) Check for eof (shouldn't happen, but if it does we'll fall into an infinite loop). 2) Use fatal instead of assert (will work if NDEBUG is ever defined and provides better diagnostics). 3) Ignore errors from close since they shouldn't matter. Closes #3679. --- src/rt/rust_util.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/rt/rust_util.h b/src/rt/rust_util.h index 018be4248eb..cf36c0b3355 100644 --- a/src/rt/rust_util.h +++ b/src/rt/rust_util.h @@ -142,15 +142,18 @@ inline void isaac_seed(rust_kernel* kernel, uint8_t* dest, size_t size) (_T("CryptReleaseContext"), CryptReleaseContext(hProv, 0)); #else int fd = open("/dev/urandom", O_RDONLY); - assert(fd > 0); + if (fd == -1) + kernel->fatal("error opening /dev/urandom: %s", strerror(errno)); size_t amount = 0; do { ssize_t ret = read(fd, dest+amount, size-amount); - assert(ret >= 0); + if (ret < 0) + kernel->fatal("error reading /dev/urandom: %s", strerror(errno)); + else if (ret == 0) + kernel->fatal("somehow hit eof reading from /dev/urandom"); amount += (size_t)ret; } while (amount < size); - int ret = close(fd); - assert(ret == 0); + (void) close(fd); #endif }