ruby-changes:40594
From: akr <ko1@a...>
Date: Thu, 19 Nov 2015 22:50:15 +0900 (JST)
Subject: [ruby-changes:40594] akr:r52673 (trunk): * ext/socket/ancdata.c: Check buffer full and ignore MSG_TRUNC flag.
akr 2015-11-19 22:49:58 +0900 (Thu, 19 Nov 2015) New Revision: 52673 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52673 Log: * ext/socket/ancdata.c: Check buffer full and ignore MSG_TRUNC flag. buffer fullness is more robust to detect the message is too big for the buffer. AIX 7.1 recvmsg doesn't set MSG_TRUNC for rflags when MSG_PEEK is given. Modified files: trunk/ChangeLog trunk/ext/socket/ancdata.c trunk/ext/socket/lib/socket.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 52672) +++ ChangeLog (revision 52673) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Nov 19 22:35:31 2015 Tanaka Akira <akr@f...> + + * ext/socket/ancdata.c: Check buffer full and ignore MSG_TRUNC flag. + buffer fullness is more robust to detect the message is too big for + the buffer. + AIX 7.1 recvmsg doesn't set MSG_TRUNC for rflags when MSG_PEEK is + given. + Thu Nov 19 21:55:11 2015 Koichi Sasada <ko1@a...> * gc.c (gc_start): force to invoke GC by GC.start Index: ext/socket/lib/socket.rb =================================================================== --- ext/socket/lib/socket.rb (revision 52672) +++ ext/socket/lib/socket.rb (revision 52673) @@ -415,7 +415,8 @@ class BasicSocket < IO https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L415 # # _maxmesglen_ and _maxcontrollen_ can be nil. # In that case, the buffer will be grown until the message is not truncated. - # Internally, MSG_PEEK is used and MSG_TRUNC/MSG_CTRUNC are checked. + # Internally, MSG_PEEK is used. + # Buffer full and MSG_CTRUNC are checked for truncation. # # recvmsg can be used to implement recv_io as follows: # Index: ext/socket/ancdata.c =================================================================== --- ext/socket/ancdata.c (revision 52672) +++ ext/socket/ancdata.c (revision 52673) @@ -1580,13 +1580,13 @@ bsock_recvmsg_internal(VALUE sock, https://github.com/ruby/ruby/blob/trunk/ext/socket/ancdata.c#L1580 if (grow_buffer) { int grown = 0; -#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL) - if (NIL_P(vmaxdatlen) && (mh.msg_flags & MSG_TRUNC)) { + if (NIL_P(vmaxdatlen) && ss != -1 && ss == (ssize_t)iov.iov_len) { if (SIZE_MAX/2 < maxdatlen) rb_raise(rb_eArgError, "max data length too big"); maxdatlen *= 2; grown = 1; } +#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL) if (NIL_P(vmaxctllen) && (mh.msg_flags & MSG_CTRUNC)) { #define BIG_ENOUGH_SPACE 65536 if (BIG_ENOUGH_SPACE < maxctllen && @@ -1606,13 +1606,6 @@ bsock_recvmsg_internal(VALUE sock, https://github.com/ruby/ruby/blob/trunk/ext/socket/ancdata.c#L1606 } #undef BIG_ENOUGH_SPACE } -#else - if (NIL_P(vmaxdatlen) && ss != -1 && ss == (ssize_t)iov.iov_len) { - if (SIZE_MAX/2 < maxdatlen) - rb_raise(rb_eArgError, "max data length too big"); - maxdatlen *= 2; - grown = 1; - } #endif if (grown) { rsock_discard_cmsg_resource(&mh, (flags & MSG_PEEK) != 0); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/