diff options
author | Kim Alvefur <zash@zash.se> | 2017-12-03 15:36:20 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2017-12-03 15:36:20 +0100 |
commit | 96d9651ece0aeb4045136c8c4e9f978eb1738334 (patch) | |
tree | 52afc3e7368a8e6e98c982bf0c11d047a3205d79 /util-src/crand.c | |
parent | abb425e70f217eb660aadb29885e07a7238b7feb (diff) | |
download | prosody-96d9651ece0aeb4045136c8c4e9f978eb1738334.tar.gz prosody-96d9651ece0aeb4045136c8c4e9f978eb1738334.zip |
util.crand: Throw an error for sizes smaller than 1 byte
Diffstat (limited to 'util-src/crand.c')
-rw-r--r-- | util-src/crand.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/util-src/crand.c b/util-src/crand.c index cdc3c211..20871f3e 100644 --- a/util-src/crand.c +++ b/util-src/crand.c @@ -69,7 +69,9 @@ int getrandom(void *buf, size_t buflen, unsigned int flags) { int Lrandom(lua_State *L) { char smallbuf[SMALLBUFSIZ]; char *buf = &smallbuf[0]; - const size_t len = luaL_checkinteger(L, 1); + const lua_Integer l = luaL_checkinteger(L, 1); + const size_t len = l; + luaL_argcheck(L, l >= 0, 1, "must be > 0"); if(len > SMALLBUFSIZ) { buf = lua_newuserdata(L, len); |