Skip to content

Commit

Permalink
Some isaac_ssed fixes:
Browse files Browse the repository at this point in the history
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 rust-lang#3679.
  • Loading branch information
jesse99 committed Nov 18, 2012
1 parent 428c58b commit 6860ffd
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/rt/rust_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 6860ffd

Please sign in to comment.