aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-12-03 15:36:20 +0100
committerKim Alvefur <zash@zash.se>2017-12-03 15:36:20 +0100
commitb11baf8702dbb7a522ab2718691a87200f27aea9 (patch)
tree52afc3e7368a8e6e98c982bf0c11d047a3205d79
parent49ac287d45c921717ed928d73198fb10df3b7785 (diff)
downloadprosody-b11baf8702dbb7a522ab2718691a87200f27aea9.tar.gz
prosody-b11baf8702dbb7a522ab2718691a87200f27aea9.zip
util.crand: Throw an error for sizes smaller than 1 byte
-rw-r--r--util-src/crand.c4
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);