Skip to content

Commit

Permalink
Ignore negative FD numbers passed to poll()
Browse files Browse the repository at this point in the history
Fixes #2401
  • Loading branch information
tbodt committed Oct 20, 2024
1 parent f1ea54d commit fc4ee06
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kernel/poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ dword_t sys_poll(addr_t fds, dword_t nfds, int_t timeout) {

for (unsigned i = 0; i < nfds; i++) {
polls[i].revents = 0;
if (f_get(polls[i].fd) == NULL)
if (polls[i].fd >= 0 && files[i] == NULL)
polls[i].revents = POLL_NVAL;
}
struct poll_context context = {polls, files, nfds};
Expand All @@ -203,6 +203,8 @@ dword_t sys_poll(addr_t fds, dword_t nfds, int_t timeout) {
fd_close(files[i]);
}
STRACE("%d end poll", current->pid);
for (unsigned i = 0; i < nfds; i++)
STRACE(" {%d, %#x}", polls[i].fd, polls[i].revents);

if (res < 0)
return res;
Expand Down

0 comments on commit fc4ee06

Please sign in to comment.