* 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.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52673 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2015-11-19 13:49:58 +00:00
parent 121b6e064a
commit 33b832979b
3 changed files with 12 additions and 10 deletions

View File

@ -1,3 +1,11 @@
Thu Nov 19 22:35:31 2015 Tanaka Akira <akr@fsij.org>
* 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@atdot.net> Thu Nov 19 21:55:11 2015 Koichi Sasada <ko1@atdot.net>
* gc.c (gc_start): force to invoke GC by GC.start * gc.c (gc_start): force to invoke GC by GC.start

View File

@ -1580,13 +1580,13 @@ bsock_recvmsg_internal(VALUE sock,
if (grow_buffer) { if (grow_buffer) {
int grown = 0; int grown = 0;
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL) if (NIL_P(vmaxdatlen) && ss != -1 && ss == (ssize_t)iov.iov_len) {
if (NIL_P(vmaxdatlen) && (mh.msg_flags & MSG_TRUNC)) {
if (SIZE_MAX/2 < maxdatlen) if (SIZE_MAX/2 < maxdatlen)
rb_raise(rb_eArgError, "max data length too big"); rb_raise(rb_eArgError, "max data length too big");
maxdatlen *= 2; maxdatlen *= 2;
grown = 1; grown = 1;
} }
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
if (NIL_P(vmaxctllen) && (mh.msg_flags & MSG_CTRUNC)) { if (NIL_P(vmaxctllen) && (mh.msg_flags & MSG_CTRUNC)) {
#define BIG_ENOUGH_SPACE 65536 #define BIG_ENOUGH_SPACE 65536
if (BIG_ENOUGH_SPACE < maxctllen && if (BIG_ENOUGH_SPACE < maxctllen &&
@ -1606,13 +1606,6 @@ bsock_recvmsg_internal(VALUE sock,
} }
#undef BIG_ENOUGH_SPACE #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 #endif
if (grown) { if (grown) {
rsock_discard_cmsg_resource(&mh, (flags & MSG_PEEK) != 0); rsock_discard_cmsg_resource(&mh, (flags & MSG_PEEK) != 0);

View File

@ -415,7 +415,8 @@ class BasicSocket < IO
# #
# _maxmesglen_ and _maxcontrollen_ can be nil. # _maxmesglen_ and _maxcontrollen_ can be nil.
# In that case, the buffer will be grown until the message is not truncated. # 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: # recvmsg can be used to implement recv_io as follows:
# #