changeset 14213:75d09be04f13 13.0

util.poll: Reject file descriptors outside of FD_SETSIZE in all methods To prevent accesses outside the bounds of the FD sets. Previously only checked on the write, but maybe this could potentially cause weird behavior as well?
author Kim Alvefur <zash@zash.se>
date Sun, 31 May 2026 11:51:22 +0200
parents c4aa9b2b4787
children 3870f944dec4 7eb0e47418ab
files util-src/poll.c
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/util-src/poll.c	Sat May 30 19:21:08 2026 +0200
+++ b/util-src/poll.c	Sun May 31 11:51:22 2026 +0200
@@ -234,6 +234,13 @@
 #endif
 #ifdef USE_SELECT
 
+	if(fd >= FD_SETSIZE) {
+		luaL_pushfail(L);
+		lua_pushstring(L, strerror(EBADF));
+		lua_pushinteger(L, EBADF);
+		return 3;
+	}
+
 	if(!FD_ISSET(fd, &state->all)) {
 		luaL_pushfail(L);
 		lua_pushstring(L, strerror(ENOENT));
@@ -327,6 +334,13 @@
 #endif
 #ifdef USE_SELECT
 
+	if(fd >= FD_SETSIZE) {
+		luaL_pushfail(L);
+		lua_pushstring(L, strerror(EBADF));
+		lua_pushinteger(L, EBADF);
+		return 3;
+	}
+
 	if(!FD_ISSET(fd, &state->all)) {
 		luaL_pushfail(L);
 		lua_pushstring(L, strerror(ENOENT));