Software /
code /
prosody
Changeset
8449:b572a708fd41
util.crand: Throw an error for sizes smaller than 1 byte
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 03 Dec 2017 15:36:20 +0100 |
parents | 8448:f516a52f19e8 |
children | 8450:3a9a3d90c44c |
files | util-src/crand.c |
diffstat | 1 files changed, 3 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/util-src/crand.c Sun Dec 03 15:21:12 2017 +0100 +++ b/util-src/crand.c Sun Dec 03 15:36:20 2017 +0100 @@ -69,7 +69,9 @@ 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);