* ext/socket/ancdata.c (rsock_recvmsg): ignore truncated part of

socket address returned from recvmsg().

* ext/socket/init.c (recvfrom_blocking): ignore truncated part of
  socket address returned from recvfrom().
  (rsock_s_recvfrom_nonblock): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39278 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2013-02-16 11:44:42 +00:00
Родитель 1061371f29
Коммит 75a5be3717
3 изменённых файлов: 27 добавлений и 3 удалений

Просмотреть файл

@ -1,3 +1,12 @@
Sat Feb 16 20:43:20 2013 Tanaka Akira <akr@fsij.org>
* ext/socket/ancdata.c (rsock_recvmsg): ignore truncated part of
socket address returned from recvmsg().
* ext/socket/init.c (recvfrom_blocking): ignore truncated part of
socket address returned from recvfrom().
(rsock_s_recvfrom_nonblock): ditto.
Sat Feb 16 20:05:26 2013 Ayumu AIZAWA <ayumu.aizawa@gmail.com>
* test/ruby/test_thread.rb: fixed typo

Просмотреть файл

@ -1362,11 +1362,17 @@ struct recvmsg_args_struct {
ssize_t
rsock_recvmsg(int socket, struct msghdr *message, int flags)
{
ssize_t ret;
socklen_t len0;
#ifdef MSG_CMSG_CLOEXEC
/* MSG_CMSG_CLOEXEC is available since Linux 2.6.23. Linux 2.6.18 silently ignore it. */
flags |= MSG_CMSG_CLOEXEC;
#endif
return recvmsg(socket, message, flags);
len0 = message->msg_namelen;
ret = recvmsg(socket, message, flags);
if (ret != -1 && len0 < message->msg_namelen)
message->msg_namelen = len0;
return ret;
}
static void *

Просмотреть файл

@ -98,8 +98,13 @@ static VALUE
recvfrom_blocking(void *data)
{
struct recvfrom_arg *arg = data;
return (VALUE)recvfrom(arg->fd, RSTRING_PTR(arg->str), RSTRING_LEN(arg->str),
arg->flags, (struct sockaddr*)&arg->buf, &arg->alen);
socklen_t len0 = arg->alen;
ssize_t ret;
ret = recvfrom(arg->fd, RSTRING_PTR(arg->str), RSTRING_LEN(arg->str),
arg->flags, (struct sockaddr*)&arg->buf, &arg->alen);
if (ret != -1 && len0 < arg->alen)
arg->alen = len0;
return (VALUE)ret;
}
VALUE
@ -182,6 +187,7 @@ rsock_s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type
long slen;
int fd, flags;
VALUE addr = Qnil;
socklen_t len0;
rb_scan_args(argc, argv, "11", &len, &flg);
@ -205,7 +211,10 @@ rsock_s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type
rb_io_check_closed(fptr);
rb_io_set_nonblock(fptr);
len0 = alen;
slen = recvfrom(fd, RSTRING_PTR(str), buflen, flags, (struct sockaddr*)&buf, &alen);
if (slen != -1 && len0 < alen)
alen = len0;
if (slen < 0) {
switch (errno) {