mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
merge revision(s) 53231,53244: [Backport #11854]
* 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@53923 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
734ac67206
commit
c9eefd5644
4 changed files with 27 additions and 7 deletions
|
|
@ -1,3 +1,9 @@
|
|||
Thu Feb 25 17:38:59 2016 Eric Wong <e@80x24.org>
|
||||
|
||||
* 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]
|
||||
|
||||
Thu Feb 25 17:33:38 2016 SHIBATA Hiroshi <hsbt@ruby-lang.org>
|
||||
|
||||
* cont.c: fix a double word typo.
|
||||
|
|
|
|||
|
|
@ -48,15 +48,18 @@ rsock_init_sock(VALUE sock, int fd)
|
|||
|
||||
if (fstat(fd, &sbuf) < 0)
|
||||
rb_sys_fail("fstat(2)");
|
||||
rb_update_max_fd(fd);
|
||||
if (!S_ISSOCK(sbuf.st_mode))
|
||||
rb_raise(rb_eArgError, "not a socket file descriptor");
|
||||
if (!S_ISSOCK(sbuf.st_mode)) {
|
||||
errno = EBADF;
|
||||
rb_sys_fail("not a socket file descriptor");
|
||||
}
|
||||
#else
|
||||
rb_update_max_fd(fd);
|
||||
if (!rb_w32_is_socket(fd))
|
||||
rb_raise(rb_eArgError, "not a socket file descriptor");
|
||||
if (!rb_w32_is_socket(fd)) {
|
||||
errno = EBADF;
|
||||
rb_sys_fail("not a socket file descriptor");
|
||||
}
|
||||
#endif
|
||||
|
||||
rb_update_max_fd(fd);
|
||||
MakeOpenFile(sock, fp);
|
||||
fp->fd = fd;
|
||||
fp->mode = FMODE_READWRITE|FMODE_DUPLEX;
|
||||
|
|
|
|||
|
|
@ -85,4 +85,15 @@ class TestSocket_BasicSocket < Test::Unit::TestCase
|
|||
}
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#define RUBY_VERSION "2.1.9"
|
||||
#define RUBY_RELEASE_DATE "2016-02-25"
|
||||
#define RUBY_PATCHLEVEL 444
|
||||
#define RUBY_PATCHLEVEL 445
|
||||
|
||||
#define RUBY_RELEASE_YEAR 2016
|
||||
#define RUBY_RELEASE_MONTH 2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue