aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);