summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-27 08:26:47 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-27 08:26:47 +0000
commitb3d126d5dea5dbfacc0cd77de12c6482e1c9e360 (patch)
treef0dfa5acfa8ba15d3b12ebfb22dbe80f2a007137 /thread.c
parent71dca4b60dafa87601df4ded2847411bb5b598da (diff)
rb_wait_for_single_fd: do not OOM or segfault with invalid FD on select()
Instead, match the poll() implementation used on Linux for now; as the Linux poll(2) manpage describes using negative FD to easily ignore an FD in a larger FD set while (sleeping the given timeout). I'm not entirely sure if matching poll() behavior is a good idea for a single FD, but it's better than segfaulting or NoMemoryError. * thread.c (init_set_fd): ignore negative FD * test/-ext-/wait_for_single_fd/test_wait_for_single_fd.rb (test_wait_for_invalid_fd): check values which may trigger segfaults or OOM git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/thread.c b/thread.c
index 76fb1360c9..4d954c76de 100644
--- a/thread.c
+++ b/thread.c
@@ -3969,6 +3969,9 @@ rb_wait_for_single_fd(int fd, int events, struct timeval *tv)
static rb_fdset_t *
init_set_fd(int fd, rb_fdset_t *fds)
{
+ if (fd < 0) {
+ return 0;
+ }
rb_fd_init(fds);
rb_fd_set(fd, fds);