# HG changeset patch # User Kim Alvefur # Date 1538930686 -7200 # Node ID 6397e965a22d94040cdcc0cc89c4dee00952d14d # Parent 6b4d28eb19cf2f459f4e10193bdda46532e82f17 net.poll: Guard against negative or too large FDs diff -r 6b4d28eb19cf -r 6397e965a22d util-src/poll.c --- a/util-src/poll.c Sun Oct 07 18:41:44 2018 +0200 +++ b/util-src/poll.c Sun Oct 07 18:44:46 2018 +0200 @@ -66,6 +66,13 @@ 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 @@ #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));