Skip to content

Commit

Permalink
socket: fix recvmsg without argument
Browse files Browse the repository at this point in the history
* 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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
normal committed Nov 17, 2015
1 parent dd2949a commit 508b5fd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Wed Nov 18 06:59:52 2015 Eric Wong <e@80x24.org>

* 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@ruby-lang.org>

* win32/win32.c (fstat): declare for mingw.
Expand Down
2 changes: 1 addition & 1 deletion ext/socket/ancdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ bsock_recvmsg_internal(VALUE sock,
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
Expand Down
4 changes: 2 additions & 2 deletions ext/socket/lib/socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def recv_nonblock(len, flag = 0, str = nil, exception: true)
# 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

Expand All @@ -441,7 +441,7 @@ def recvmsg(dlen = 4096, flags = 0, clen = nil, scm_rights: false)
# 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
Expand Down
16 changes: 16 additions & 0 deletions test/socket/test_socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -653,4 +653,20 @@ def test_tcp_server_sockets_in_rescue
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)

0 comments on commit 508b5fd

Please sign in to comment.