ruby-changes:53368
From: mame <ko1@a...>
Date: Wed, 7 Nov 2018 07:56:03 +0900 (JST)
Subject: [ruby-changes:53368] mame:r65584 (trunk): Revert "thread.c (rb_wait_for_single_fd): no point initializing pollfd.revents"
mame 2018-11-07 07:55:57 +0900 (Wed, 07 Nov 2018) New Revision: 65584 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65584 Log: Revert "thread.c (rb_wait_for_single_fd): no point initializing pollfd.revents" It may cause an access to uninitialized variables. The call to ppoll will set the `revents` field, but ppoll is not always called because it is in the guard `!RUBY_VM_INTERRUPTED(th->ec)`. This issue was found by Coverity Scan. Modified files: trunk/thread.c Index: thread.c =================================================================== --- thread.c (revision 65583) +++ thread.c (revision 65584) @@ -4043,10 +4043,12 @@ rb_wait_for_single_fd(int fd, int events https://github.com/ruby/ruby/blob/trunk/thread.c#L4043 fds[0].fd = fd; fds[0].events = (short)events; do { + fds[0].revents = 0; fds[1].fd = rb_sigwait_fd_get(th); if (fds[1].fd >= 0) { fds[1].events = POLLIN; + fds[1].revents = 0; nfds = 2; ubf = ubf_sigwait; } @@ -4070,6 +4072,7 @@ rb_wait_for_single_fd(int fd, int events https://github.com/ruby/ruby/blob/trunk/thread.c#L4072 if (fds[1].fd >= 0) { if (result > 0 && fds[1].revents) { result--; + fds[1].revents = 0; } (void)check_signals_nogvl(th, fds[1].fd); rb_sigwait_fd_put(th, fds[1].fd); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/