From 6860ffd639c8660be956d7bed6f562c640e6b958 Mon Sep 17 00:00:00 2001 From: Jesse Jones Date: Sat, 17 Nov 2012 16:07:49 -0800 Subject: [PATCH 1/2] 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 018be4248eb98..cf36c0b335507 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 } From 2ea7aedf89a8a9258523c0e0fc2ee09fe2eadb4c Mon Sep 17 00:00:00 2001 From: Jesse Jones Date: Sat, 17 Nov 2012 16:50:22 -0800 Subject: [PATCH 2/2] Log errors from close instead of ignoring them. They shouldn't matter but there have been errors on Macs so logging them may help root cause the issue. --- src/rt/rust_util.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rt/rust_util.h b/src/rt/rust_util.h index cf36c0b335507..4dc29e3c56023 100644 --- a/src/rt/rust_util.h +++ b/src/rt/rust_util.h @@ -153,7 +153,10 @@ inline void isaac_seed(rust_kernel* kernel, uint8_t* dest, size_t size) kernel->fatal("somehow hit eof reading from /dev/urandom"); amount += (size_t)ret; } while (amount < size); - (void) close(fd); + int ret = close(fd); + if (ret != 0) + kernel->log(log_warn, "error closing /dev/urandom: %s", + strerror(errno)); #endif }