# HG changeset patch # User Kim Alvefur # Date 1512311780 -3600 # Node ID b572a708fd41207051d18421c7fecd6622d8b353 # Parent f516a52f19e82ff80317e3da24c47d92fb8648ef util.crand: Throw an error for sizes smaller than 1 byte diff -r f516a52f19e8 -r b572a708fd41 util-src/crand.c --- 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);