diff options
author | Kim Alvefur <zash@zash.se> | 2018-10-07 18:44:46 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2018-10-07 18:44:46 +0200 |
commit | e70b1af98af0c5d82049463616f5db750a1ab3a8 (patch) | |
tree | e0e31f1ef99a81b03c135f4bf302fc8a1fa463ae /util-src/poll.c | |
parent | b39130c595085797ba07abe5a3d016dacd5e0b09 (diff) | |
download | prosody-e70b1af98af0c5d82049463616f5db750a1ab3a8.tar.gz prosody-e70b1af98af0c5d82049463616f5db750a1ab3a8.zip |
net.poll: Guard against negative or too large FDs
Diffstat (limited to 'util-src/poll.c')
-rw-r--r-- | util-src/poll.c | 14 |
1 files changed, 14 insertions, 0 deletions
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)); |