From: Eric Wong <normalperson@yhbt.net>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:72419] Re: [Ruby trunk - Bug #11854] [Open] Socket.for_fd(-1) causes segmentaion fault on mingw32.
Date: Mon, 21 Dec 2015 10:08:45 +0000 [thread overview]
Message-ID: <20151221100845.GA14896@dcvr.yhbt.net> (raw)
In-Reply-To: <redmine.issue-11854.20151221094324.4bd79f0d833f48e0@ruby-lang.org>
Proposed fix (not sure about the error message saying "fstat(2)", now...)
Subject: [PATCH] avoid rb_bug on BasicSocket.for_fd(-1)
* ext/socket/init.c (rsock_init_sock): check FD after validating
* test/socket/test_basicsocket.rb (test_for_fd): new
[ruby-core:72418] [Bug #11854]
---
ext/socket/init.c | 2 +-
test/socket/test_basicsocket.rb | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/ext/socket/init.c b/ext/socket/init.c
index d071102..bd06926 100644
--- a/ext/socket/init.c
+++ b/ext/socket/init.c
@@ -61,10 +61,10 @@ rsock_init_sock(VALUE sock, int fd)
{
rb_io_t *fp;
- rb_update_max_fd(fd);
if (!is_socket(fd))
rb_raise(rb_eArgError, "not a socket file descriptor");
+ rb_update_max_fd(fd);
MakeOpenFile(sock, fp);
fp->fd = fd;
fp->mode = FMODE_READWRITE|FMODE_DUPLEX;
diff --git a/test/socket/test_basicsocket.rb b/test/socket/test_basicsocket.rb
index 227034e..52732f1 100644
--- a/test/socket/test_basicsocket.rb
+++ b/test/socket/test_basicsocket.rb
@@ -133,4 +133,15 @@ def test_close_write
end
end
+ def test_for_fd
+ assert_raise(Errno::EBADF, '[ruby-core:72418] [Bug #11854]') do
+ BasicSocket.for_fd(-1)
+ end
+ inet_stream do |sock|
+ s = BasicSocket.for_fd(sock.fileno)
+ assert_instance_of BasicSocket, s
+ s.autoclose = false
+ sock.close
+ end
+ end
end if defined?(BasicSocket)
--
EW
next prev parent reply other threads:[~2015-12-21 9:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-11854.20151221094324@ruby-lang.org>
2015-12-21 9:43 ` [ruby-core:72418] [Ruby trunk - Bug #11854] [Open] Socket.for_fd(-1) causes segmentaion fault on mingw32 phasis
2015-12-21 10:08 ` Eric Wong [this message]
2015-12-21 18:57 ` [ruby-core:72422] [Ruby trunk - Bug #11854] " normalperson
2016-02-25 8:44 ` [ruby-core:73975] [Ruby trunk Bug#11854] " usa
2016-03-08 18:50 ` [ruby-core:74226] " nagachika00
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151221100845.GA14896@dcvr.yhbt.net \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).