Changeset

9447:6397e965a22d

net.poll: Guard against negative or too large FDs
author Kim Alvefur <zash@zash.se>
date Sun, 07 Oct 2018 18:44:46 +0200
parents 9446:6b4d28eb19cf
children 9448:352e8b75c1ae
files util-src/poll.c
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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));