summaryrefslogtreecommitdiff
path: root/ext/socket/init.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-16 11:44:42 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-16 11:44:42 +0000
commit75a5be3717d15c468beccab2ba618b01f44d56ec (patch)
treec5a77076f4a1618ae5563f7fd16bd55a8ed5f00f /ext/socket/init.c
parent1061371f29baabd89c60d2d364947015b928d794 (diff)
* 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
Diffstat (limited to 'ext/socket/init.c')
-rw-r--r--ext/socket/init.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/ext/socket/init.c b/ext/socket/init.c
index ab3fcf2..fc3ab49 100644
--- a/ext/socket/init.c
+++ b/ext/socket/init.c
@@ -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) {