summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2021-11-11 01:20:46 +1300
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2021-11-11 13:35:16 +1300
commit51c67ee61a57093cfd6f0e06a5aff77d479a37e1 (patch)
treebb81fefcc1f827969a28d7a97a3b0c9d3ca929a1 /io.c
parentd5dd87d0db7270d5845ec016b3436fba608e27d7 (diff)
Don't allow `fd == -1` to propagate to system calls.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5100
Diffstat (limited to 'io.c')
-rw-r--r--io.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/io.c b/io.c
index 8a4df453ac..366225089c 100644
--- a/io.c
+++ b/io.c
@@ -11270,9 +11270,12 @@ nogvl_wait_for(VALUE th, rb_io_t *fptr, short events)
return RTEST(args.result);
}
+ int fd = fptr->fd;
+ if (fd == -1) return 0;
+
struct pollfd fds;
- fds.fd = fptr->fd;
+ fds.fd = fd;
fds.events = events;
return poll(&fds, 1, -1);
@@ -11289,18 +11292,21 @@ nogvl_wait_for(VALUE th, rb_io_t *fptr, short events)
return RTEST(args.result);
}
+ int fd = fptr->fd;
+ if (fd == -1) return 0;
+
rb_fdset_t fds;
int ret;
rb_fd_init(&fds);
- rb_fd_set(fptr->fd, &fds);
+ rb_fd_set(fd, &fds);
switch (events) {
case RB_WAITFD_IN:
- ret = rb_fd_select(fptr->fd + 1, &fds, 0, 0, 0);
+ ret = rb_fd_select(fd + 1, &fds, 0, 0, 0);
break;
case RB_WAITFD_OUT:
- ret = rb_fd_select(fptr->fd + 1, 0, &fds, 0, 0);
+ ret = rb_fd_select(fd + 1, 0, &fds, 0, 0);
break;
default:
VM_UNREACHABLE(nogvl_wait_for);