diff options
author | Kim Alvefur <zash@zash.se> | 2017-12-02 10:58:37 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2017-12-02 10:58:37 +0100 |
commit | 1539346aadf92a954bf2562d43b46fa8329e54d5 (patch) | |
tree | d1fe92be6c806689d4639d9a5081bd5117c40aaa /util-src/crand.c | |
parent | 8053e6cd90838ef83e27056840af3b7b43188d9b (diff) | |
download | prosody-1539346aadf92a954bf2562d43b46fa8329e54d5.tar.gz prosody-1539346aadf92a954bf2562d43b46fa8329e54d5.zip |
util.crand: Try getrandom() again until buffer is filled
Diffstat (limited to 'util-src/crand.c')
-rw-r--r-- | util-src/crand.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/util-src/crand.c b/util-src/crand.c index 762f7454..2996b84d 100644 --- a/util-src/crand.c +++ b/util-src/crand.c @@ -68,12 +68,22 @@ int Lrandom(lua_State *L) { * This acts like a read from /dev/urandom with the exception that it * *does* block if the entropy pool is not yet initialized. */ - ret = getrandom(buf, len, 0); + int left = len; + char *b = buf; - if(ret < 0) { - lua_pushstring(L, strerror(errno)); - return lua_error(L); - } + do { + ret = getrandom(b, left, 0); + + if(ret < 0) { + lua_pushstring(L, strerror(errno)); + return lua_error(L); + } + + b += ret; + left -= ret; + } while(left > 0); + + ret = len; #elif defined(WITH_ARC4RANDOM) arc4random_buf(buf, len); |