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

ruby-changes:40546

From: normal <ko1@a...>
Date: Wed, 18 Nov 2015 07:00:52 +0900 (JST)
Subject: [ruby-changes:40546] normal:r52625 (trunk): socket: fix recvmsg without argument

normal	2015-11-18 07:00:23 +0900 (Wed, 18 Nov 2015)

  New Revision: 52625

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

  Log:
    socket: fix recvmsg without argument
    
    * ext/socket/ancdata.c (bsock_recvmsg_internal): grow buffer
      on unspecified maxdatlen
      [ruby-core:71517] [Bug #11701]
    * ext/socket/lib/socket.rb (Socket#recvmsg): nil default for dlen
      (Socket#recvmsg_nonblock): ditto
    * test/socket/test_socket.rb (test_recvmsg_udp_no_arg): new test

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/ancdata.c
    trunk/ext/socket/lib/socket.rb
    trunk/test/socket/test_socket.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52624)
+++ ChangeLog	(revision 52625)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Nov 18 06:59:52 2015  Eric Wong  <e@8...>
+
+	* ext/socket/ancdata.c (bsock_recvmsg_internal): grow buffer
+	  on unspecified maxdatlen
+	  [ruby-core:71517] [Bug #11701]
+	* ext/socket/lib/socket.rb (Socket#recvmsg): nil default for dlen
+	  (Socket#recvmsg_nonblock): ditto
+	* test/socket/test_socket.rb (test_recvmsg_udp_no_arg): new test
+
 Tue Nov 17 19:50:06 2015  NAKAMURA Usaku  <usa@r...>
 
 	* win32/win32.c (fstat): declare for mingw.
Index: ext/socket/lib/socket.rb
===================================================================
--- ext/socket/lib/socket.rb	(revision 52624)
+++ ext/socket/lib/socket.rb	(revision 52625)
@@ -425,7 +425,7 @@ class BasicSocket < IO https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L425
   #       return ancdata.unix_rights[0]
   #     end
   #   }
-  def recvmsg(dlen = 4096, flags = 0, clen = nil, scm_rights: false)
+  def recvmsg(dlen = nil, flags = 0, clen = nil, scm_rights: false)
     __recvmsg(dlen, flags, clen, scm_rights)
   end
 
@@ -441,7 +441,7 @@ class BasicSocket < IO https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L441
   # By specifying `exception: false`, the _opts_ hash allows you to indicate
   # that recvmsg_nonblock should not raise an IO::WaitWritable exception, but
   # return the symbol :wait_writable instead.
-  def recvmsg_nonblock(dlen = 4096, flags = 0, clen = nil,
+  def recvmsg_nonblock(dlen = nil, flags = 0, clen = nil,
                        scm_rights: false, exception: true)
     __recvmsg_nonblock(dlen, flags, clen, scm_rights, exception)
   end
Index: ext/socket/ancdata.c
===================================================================
--- ext/socket/ancdata.c	(revision 52624)
+++ ext/socket/ancdata.c	(revision 52625)
@@ -1465,7 +1465,7 @@ bsock_recvmsg_internal(VALUE sock, https://github.com/ruby/ruby/blob/trunk/ext/socket/ancdata.c#L1465
     int gc_done = 0;
 #endif
 
-    maxdatlen = NUM2SIZET(vmaxdatlen);
+    maxdatlen = NIL_P(vmaxdatlen) ? 4061 : NUM2SIZET(vmaxdatlen);
 #if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
     maxctllen = NIL_P(vmaxctllen) ? 4096 : NUM2SIZET(vmaxctllen);
 #else
Index: test/socket/test_socket.rb
===================================================================
--- test/socket/test_socket.rb	(revision 52624)
+++ test/socket/test_socket.rb	(revision 52625)
@@ -653,4 +653,20 @@ class TestSocket < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/socket/test_socket.rb#L653
     end
   end
 
+  def test_recvmsg_udp_no_arg
+    n = 4097
+    s1 = Addrinfo.udp("127.0.0.1", 0).bind
+    s2 = s1.connect_address.connect
+    s2.send("a" * n, 0)
+    ret = s1.recvmsg
+    assert_equal n, ret[0].bytesize, '[ruby-core:71517] [Bug #11701]'
+
+    s2.send("a" * n, 0)
+    IO.select([s1])
+    ret = s1.recvmsg_nonblock
+    assert_equal n, ret[0].bytesize, 'non-blocking should also grow'
+  ensure
+    s1.close
+    s2.close
+  end
 end if defined?(Socket)

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

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