Skip to content

Commit 8adacc0

Browse files
jesse99brson
authored andcommitted
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.
1 parent 3ac90ec commit 8adacc0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/rt/rust_util.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,18 @@ inline void isaac_seed(rust_kernel* kernel, uint8_t* dest, size_t size)
142142
(_T("CryptReleaseContext"), CryptReleaseContext(hProv, 0));
143143
#else
144144
int fd = open("/dev/urandom", O_RDONLY);
145-
assert(fd > 0);
145+
if (fd == -1)
146+
kernel->fatal("error opening /dev/urandom: %s", strerror(errno));
146147
size_t amount = 0;
147148
do {
148149
ssize_t ret = read(fd, dest+amount, size-amount);
149-
assert(ret >= 0);
150+
if (ret < 0)
151+
kernel->fatal("error reading /dev/urandom: %s", strerror(errno));
152+
else if (ret == 0)
153+
kernel->fatal("somehow hit eof reading from /dev/urandom");
150154
amount += (size_t)ret;
151155
} while (amount < size);
152-
int ret = close(fd);
153-
assert(ret == 0);
156+
(void) close(fd);
154157
#endif
155158
}
156159

0 commit comments

Comments
 (0)