Comparison

util-src/poll.c @ 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
parent 9446:6b4d28eb19cf
child 9448:352e8b75c1ae
comparison
equal deleted inserted replaced
9446:6b4d28eb19cf 9447:6397e965a22d
64 int fd = luaL_checkinteger(L, 2); 64 int fd = luaL_checkinteger(L, 2);
65 65
66 int wantread = lua_toboolean(L, 3); 66 int wantread = lua_toboolean(L, 3);
67 int wantwrite = lua_toboolean(L, 4); 67 int wantwrite = lua_toboolean(L, 4);
68 68
69 if(fd < 0) {
70 lua_pushnil(L);
71 lua_pushstring(L, strerror(EBADF));
72 lua_pushinteger(L, EBADF);
73 return 3;
74 }
75
69 #ifdef USE_EPOLL 76 #ifdef USE_EPOLL
70 struct epoll_event event; 77 struct epoll_event event;
71 event.data.fd = fd; 78 event.data.fd = fd;
72 event.events = (wantread ? EPOLLIN : 0) | (wantwrite ? EPOLLOUT : 0); 79 event.events = (wantread ? EPOLLIN : 0) | (wantwrite ? EPOLLOUT : 0);
73 80
85 92
86 lua_pushboolean(L, 1); 93 lua_pushboolean(L, 1);
87 return 1; 94 return 1;
88 95
89 #else 96 #else
97
98 if(fd > FD_SETSIZE) {
99 lua_pushnil(L);
100 lua_pushstring(L, strerror(EBADF));
101 lua_pushinteger(L, EBADF);
102 return 3;
103 }
90 104
91 if(FD_ISSET(fd, &state->all)) { 105 if(FD_ISSET(fd, &state->all)) {
92 lua_pushnil(L); 106 lua_pushnil(L);
93 lua_pushstring(L, strerror(EEXIST)); 107 lua_pushstring(L, strerror(EEXIST));
94 lua_pushinteger(L, EEXIST); 108 lua_pushinteger(L, EEXIST);