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 | b11baf8702dbb7a522ab2718691a87200f27aea9 (patch) | |
tree | 52afc3e7368a8e6e98c982bf0c11d047a3205d79 /util-src | |
parent | 49ac287d45c921717ed928d73198fb10df3b7785 (diff) | |
download | prosody-b11baf8702dbb7a522ab2718691a87200f27aea9.tar.gz prosody-b11baf8702dbb7a522ab2718691a87200f27aea9.zip |
util.crand: Throw an error for sizes smaller than 1 byte
Diffstat (limited to 'util-src')
-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); |