From ceadb9c57cec7f8a3b01a2fe4aa71f104076d29f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 7 Oct 2018 18:44:46 +0200 Subject: net.poll: Guard against negative or too large FDs --- util-src/poll.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/util-src/poll.c b/util-src/poll.c index 71d5c3a2..47a994c1 100644 --- a/util-src/poll.c +++ b/util-src/poll.c @@ -66,6 +66,13 @@ int Ladd(lua_State *L) { int wantread = lua_toboolean(L, 3); int wantwrite = lua_toboolean(L, 4); + if(fd < 0) { + lua_pushnil(L); + lua_pushstring(L, strerror(EBADF)); + lua_pushinteger(L, EBADF); + return 3; + } + #ifdef USE_EPOLL struct epoll_event event; event.data.fd = fd; @@ -88,6 +95,13 @@ int Ladd(lua_State *L) { #else + if(fd > FD_SETSIZE) { + lua_pushnil(L); + lua_pushstring(L, strerror(EBADF)); + lua_pushinteger(L, EBADF); + return 3; + } + if(FD_ISSET(fd, &state->all)) { lua_pushnil(L); lua_pushstring(L, strerror(EEXIST)); -- cgit v1.2.3