aboutsummaryrefslogtreecommitdiffstats
path: root/util-src/poll.c
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-10-07 18:44:46 +0200
committerKim Alvefur <zash@zash.se>2018-10-07 18:44:46 +0200
commitceadb9c57cec7f8a3b01a2fe4aa71f104076d29f (patch)
treee0e31f1ef99a81b03c135f4bf302fc8a1fa463ae /util-src/poll.c
parent31c8b1aca33712183abfd3c0ca72759ce1d9cda9 (diff)
downloadprosody-ceadb9c57cec7f8a3b01a2fe4aa71f104076d29f.tar.gz
prosody-ceadb9c57cec7f8a3b01a2fe4aa71f104076d29f.zip
net.poll: Guard against negative or too large FDs
Diffstat (limited to 'util-src/poll.c')
-rw-r--r--util-src/poll.c14
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));