[前][次][番号順一覧][スレッド一覧]

ruby-changes:69689

From: Samuel <ko1@a...>
Date: Thu, 11 Nov 2021 09:35:32 +0900 (JST)
Subject: [ruby-changes:69689] 51c67ee61a (master): Don't allow `fd == -1` to propagate to system calls.

https://git.ruby-lang.org/ruby.git/commit/?id=51c67ee61a

From 51c67ee61a57093cfd6f0e06a5aff77d479a37e1 Mon Sep 17 00:00:00 2001
From: Samuel Williams <samuel.williams@o...>
Date: Thu, 11 Nov 2021 01:20:46 +1300
Subject: Don't allow `fd == -1` to propagate to system calls.

---
 io.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/io.c b/io.c
index 8a4df453ace..366225089c0 100644
--- a/io.c
+++ b/io.c
@@ -11270,9 +11270,12 @@ nogvl_wait_for(VALUE th, rb_io_t *fptr, short events) https://github.com/ruby/ruby/blob/trunk/io.c#L11270
         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) https://github.com/ruby/ruby/blob/trunk/io.c#L11292
         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);
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]