diff options
| author | Ben Blum <bblum@andrew.cmu.edu> | 2012-07-25 18:01:48 -0400 |
|---|---|---|
| committer | Ben Blum <bblum@andrew.cmu.edu> | 2012-07-25 18:03:00 -0400 |
| commit | 60d682b57759a4fd3b6f666963e40ba457c2e4fc (patch) | |
| tree | 63c0d14cb2462b0763bba1da7bc90531f81c6f1d | |
| parent | 4378e7ead19b48bc13cb196e3926a8cda3432ec8 (diff) | |
| download | rust-60d682b57759a4fd3b6f666963e40ba457c2e4fc.tar.gz rust-60d682b57759a4fd3b6f666963e40ba457c2e4fc.zip | |
Fix asserts & short-read bug in isaac_seed (#2870)
| -rw-r--r-- | src/rt/rust_builtin.cpp | 2 | ||||
| -rw-r--r-- | src/rt/rust_util.h | 15 |
2 files changed, 11 insertions, 6 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index f9d1f71f0ac..f9c95db1d04 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -182,7 +182,7 @@ rand_seed() { rust_vec *v = (rust_vec *) task->kernel->malloc(vec_size<uint8_t>(size), "rand_seed"); v->fill = v->alloc = size; - isaac_seed(task->kernel, (uint8_t*) &v->data); + isaac_seed(task->kernel, (uint8_t*) &v->data, size); return v; } diff --git a/src/rt/rust_util.h b/src/rt/rust_util.h index e2c75d0cae4..018be4248eb 100644 --- a/src/rt/rust_util.h +++ b/src/rt/rust_util.h @@ -128,9 +128,8 @@ inline size_t get_box_size(size_t body_size, size_t body_align) { // Initialization helpers for ISAAC RNG -inline void isaac_seed(rust_kernel* kernel, uint8_t* dest) +inline void isaac_seed(rust_kernel* kernel, uint8_t* dest, size_t size) { - size_t size = sizeof(ub4) * RANDSIZ; #ifdef __WIN32__ HCRYPTPROV hProv; kernel->win32_require @@ -144,8 +143,14 @@ inline void isaac_seed(rust_kernel* kernel, uint8_t* dest) #else int fd = open("/dev/urandom", O_RDONLY); assert(fd > 0); - assert(read(fd, dest, size) == (int) size); - assert(close(fd) == 0); + size_t amount = 0; + do { + ssize_t ret = read(fd, dest+amount, size-amount); + assert(ret >= 0); + amount += (size_t)ret; + } while (amount < size); + int ret = close(fd); + assert(ret == 0); #endif } @@ -167,7 +172,7 @@ isaac_init(rust_kernel *kernel, randctx *rctx, rust_vec_box* user_seed) seed = (seed + 0x7ed55d16) + (seed << 12); } } else { - isaac_seed(kernel, (uint8_t*) &rctx->randrsl); + isaac_seed(kernel, (uint8_t*) &rctx->randrsl, sizeof(rctx->randrsl)); } randinit(rctx, 1); |
