[前][次][番号順一覧][スレッド一覧]

ruby-changes:27226

From: akr <ko1@a...>
Date: Sat, 16 Feb 2013 20:44:55 +0900 (JST)
Subject: [ruby-changes:27226] akr:r39278 (trunk): * ext/socket/ancdata.c (rsock_recvmsg): ignore truncated part of

akr	2013-02-16 20:44:42 +0900 (Sat, 16 Feb 2013)

  New Revision: 39278

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39278

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

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/ancdata.c
    trunk/ext/socket/init.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39277)
+++ ChangeLog	(revision 39278)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Feb 16 20:43:20 2013  Tanaka Akira  <akr@f...>
+
+	* 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@g...>
 
 	* test/ruby/test_thread.rb: fixed typo
Index: ext/socket/init.c
===================================================================
--- ext/socket/init.c	(revision 39277)
+++ ext/socket/init.c	(revision 39278)
@@ -98,8 +98,13 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L98
 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, in https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L187
     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, in https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L211
 
     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) {
Index: ext/socket/ancdata.c
===================================================================
--- ext/socket/ancdata.c	(revision 39277)
+++ ext/socket/ancdata.c	(revision 39278)
@@ -1362,11 +1362,17 @@ struct recvmsg_args_struct { https://github.com/ruby/ruby/blob/trunk/ext/socket/ancdata.c#L1362
 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 *

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]