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