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

ruby-changes:41964

From: nagachika <ko1@a...>
Date: Wed, 9 Mar 2016 03:49:56 +0900 (JST)
Subject: [ruby-changes:41964] nagachika:r54038 (ruby_2_2): merge revision(s) 52605, 53231, 53244: [Backport #11854]

nagachika	2016-03-09 03:49:52 +0900 (Wed, 09 Mar 2016)

  New Revision: 54038

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54038

  Log:
    merge revision(s) 52605,53231,53244: [Backport #11854]
    
    init.c: is_socket
    
    * ext/socket/init.c (is_socket): extract predicate to see if the
      given fd is a socket.
    * 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]

  Modified directories:
    branches/ruby_2_2/
  Modified files:
    branches/ruby_2_2/ChangeLog
    branches/ruby_2_2/ext/socket/init.c
    branches/ruby_2_2/test/socket/test_basicsocket.rb
    branches/ruby_2_2/version.h
Index: ruby_2_2/test/socket/test_basicsocket.rb
===================================================================
--- ruby_2_2/test/socket/test_basicsocket.rb	(revision 54037)
+++ ruby_2_2/test/socket/test_basicsocket.rb	(revision 54038)
@@ -85,4 +85,15 @@ class TestSocket_BasicSocket < Test::Uni https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/socket/test_basicsocket.rb#L85
       }
     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)
Index: ruby_2_2/ext/socket/init.c
===================================================================
--- ruby_2_2/ext/socket/init.c	(revision 54037)
+++ ruby_2_2/ext/socket/init.c	(revision 54038)
@@ -39,24 +39,31 @@ rsock_raise_socket_error(const char *rea https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ext/socket/init.c#L39
     rb_raise(rb_eSocket, "%s: %s", reason, gai_strerror(error));
 }
 
-VALUE
-rsock_init_sock(VALUE sock, int fd)
+#ifdef _WIN32
+#define is_socket(fd) rb_w32_is_socket(fd)
+#else
+static int
+is_socket(int fd)
 {
-    rb_io_t *fp;
-#ifndef _WIN32
     struct stat sbuf;
 
     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");
-#else
-    rb_update_max_fd(fd);
-    if (!rb_w32_is_socket(fd))
-        rb_raise(rb_eArgError, "not a socket file descriptor");
+    return S_ISSOCK(sbuf.st_mode);
+}
 #endif
 
+VALUE
+rsock_init_sock(VALUE sock, int fd)
+{
+    rb_io_t *fp;
+
+    if (!is_socket(fd)) {
+	errno = EBADF;
+	rb_sys_fail("not a socket file descriptor");
+    }
+
+    rb_update_max_fd(fd);
     MakeOpenFile(sock, fp);
     fp->fd = fd;
     fp->mode = FMODE_READWRITE|FMODE_DUPLEX;
Index: ruby_2_2/version.h
===================================================================
--- ruby_2_2/version.h	(revision 54037)
+++ ruby_2_2/version.h	(revision 54038)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1
 #define RUBY_VERSION "2.2.5"
 #define RUBY_RELEASE_DATE "2016-03-09"
-#define RUBY_PATCHLEVEL 242
+#define RUBY_PATCHLEVEL 243
 
 #define RUBY_RELEASE_YEAR 2016
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_2/ChangeLog
===================================================================
--- ruby_2_2/ChangeLog	(revision 54037)
+++ ruby_2_2/ChangeLog	(revision 54038)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1
+Wed Mar  9 03:41:27 2016  Eric Wong  <e@8...>
+
+	* 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]
+
 Wed Mar  9 03:34:54 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* re.c (reg_names_iter): should consider encoding of regexp.

Property changes on: ruby_2_2
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r52605,53231,53244


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

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