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

ruby-changes:26941

From: akr <ko1@a...>
Date: Wed, 30 Jan 2013 21:02:02 +0900 (JST)
Subject: [ruby-changes:26941] akr:r38993 (trunk): * ext/socket/basicsocket.c (bsock_getsockname): ignore truncated

akr	2013-01-30 21:01:51 +0900 (Wed, 30 Jan 2013)

  New Revision: 38993

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

  Log:
    * ext/socket/basicsocket.c (bsock_getsockname): ignore truncated
      part of socket address.
      (bsock_getpeername): ditto.
      (bsock_local_address): ditto.
      (bsock_remote_address): ditto.
    
    * ext/socket/unixsocket.c (unix_path): ditto.
      (unix_addr): ditto.
      (unix_peeraddr): ditto.
    
    * ext/socket/init.c (cloexec_accept): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/basicsocket.c
    trunk/ext/socket/init.c
    trunk/ext/socket/unixsocket.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38992)
+++ ChangeLog	(revision 38993)
@@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jan 30 20:58:50 2013  Tanaka Akira  <akr@f...>
+
+	* ext/socket/basicsocket.c (bsock_getsockname): ignore truncated
+	  part of socket address.
+	  (bsock_getpeername): ditto.
+	  (bsock_local_address): ditto.
+	  (bsock_remote_address): ditto.
+
+	* ext/socket/unixsocket.c (unix_path): ditto.
+	  (unix_addr): ditto.
+	  (unix_peeraddr): ditto.
+
+	* ext/socket/init.c (cloexec_accept): ditto.
+
 Wed Jan 30 17:08:20 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* include/ruby/win32.h (fstat): revert r37337, which uses _fstati64()
Index: ext/socket/init.c
===================================================================
--- ext/socket/init.c	(revision 38992)
+++ ext/socket/init.c	(revision 38993)
@@ -481,6 +481,8 @@ static int https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L481
 cloexec_accept(int socket, struct sockaddr *address, socklen_t *address_len)
 {
     int ret;
+    socklen_t len0 = 0;
+    if (address_len) len0 = *address_len;
 #ifdef HAVE_ACCEPT4
     static int try_accept4 = 1;
     if (try_accept4) {
@@ -489,6 +491,7 @@ cloexec_accept(int socket, struct sockad https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L491
         if (ret != -1) {
             if (ret <= 2)
                 rb_maygvl_fd_fix_cloexec(ret);
+            if (address_len && len0 < *address_len) *address_len = len0;
             return ret;
         }
         if (errno == ENOSYS) {
@@ -503,6 +506,7 @@ cloexec_accept(int socket, struct sockad https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L506
     ret = accept(socket, address, address_len);
 #endif
     if (ret == -1) return -1;
+    if (address_len && len0 < *address_len) *address_len = len0;
     rb_maygvl_fd_fix_cloexec(ret);
     return ret;
 }
Index: ext/socket/basicsocket.c
===================================================================
--- ext/socket/basicsocket.c	(revision 38992)
+++ ext/socket/basicsocket.c	(revision 38993)
@@ -358,11 +358,13 @@ bsock_getsockname(VALUE sock) https://github.com/ruby/ruby/blob/trunk/ext/socket/basicsocket.c#L358
 {
     struct sockaddr_storage buf;
     socklen_t len = (socklen_t)sizeof buf;
+    socklen_t len0 = len;
     rb_io_t *fptr;
 
     GetOpenFile(sock, fptr);
     if (getsockname(fptr->fd, (struct sockaddr*)&buf, &len) < 0)
 	rb_sys_fail("getsockname(2)");
+    if (len0 < len) len = len0;
     return rb_str_new((char*)&buf, len);
 }
 
@@ -387,11 +389,13 @@ bsock_getpeername(VALUE sock) https://github.com/ruby/ruby/blob/trunk/ext/socket/basicsocket.c#L389
 {
     struct sockaddr_storage buf;
     socklen_t len = (socklen_t)sizeof buf;
+    socklen_t len0 = len;
     rb_io_t *fptr;
 
     GetOpenFile(sock, fptr);
     if (getpeername(fptr->fd, (struct sockaddr*)&buf, &len) < 0)
 	rb_sys_fail("getpeername(2)");
+    if (len0 < len) len = len0;
     return rb_str_new((char*)&buf, len);
 }
 
@@ -475,11 +479,13 @@ bsock_local_address(VALUE sock) https://github.com/ruby/ruby/blob/trunk/ext/socket/basicsocket.c#L479
 {
     struct sockaddr_storage buf;
     socklen_t len = (socklen_t)sizeof buf;
+    socklen_t len0 = len;
     rb_io_t *fptr;
 
     GetOpenFile(sock, fptr);
     if (getsockname(fptr->fd, (struct sockaddr*)&buf, &len) < 0)
 	rb_sys_fail("getsockname(2)");
+    if (len0 < len) len = len0;
     return rsock_fd_socket_addrinfo(fptr->fd, (struct sockaddr *)&buf, len);
 }
 
@@ -507,11 +513,13 @@ bsock_remote_address(VALUE sock) https://github.com/ruby/ruby/blob/trunk/ext/socket/basicsocket.c#L513
 {
     struct sockaddr_storage buf;
     socklen_t len = (socklen_t)sizeof buf;
+    socklen_t len0 = len;
     rb_io_t *fptr;
 
     GetOpenFile(sock, fptr);
     if (getpeername(fptr->fd, (struct sockaddr*)&buf, &len) < 0)
 	rb_sys_fail("getpeername(2)");
+    if (len0 < len) len = len0;
     return rsock_fd_socket_addrinfo(fptr->fd, (struct sockaddr *)&buf, len);
 }
 
Index: ext/socket/unixsocket.c
===================================================================
--- ext/socket/unixsocket.c	(revision 38992)
+++ ext/socket/unixsocket.c	(revision 38993)
@@ -120,8 +120,10 @@ unix_path(VALUE sock) https://github.com/ruby/ruby/blob/trunk/ext/socket/unixsocket.c#L120
     if (NIL_P(fptr->pathv)) {
 	struct sockaddr_un addr;
 	socklen_t len = (socklen_t)sizeof(addr);
+	socklen_t len0 = len;
 	if (getsockname(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
 	    rb_sys_fail(0);
+        if (len0 < len) len = len0;
 	fptr->pathv = rb_obj_freeze(rsock_unixpath_str(&addr, len));
     }
     return rb_str_dup(fptr->pathv);
@@ -424,11 +426,13 @@ unix_addr(VALUE sock) https://github.com/ruby/ruby/blob/trunk/ext/socket/unixsocket.c#L426
     rb_io_t *fptr;
     struct sockaddr_un addr;
     socklen_t len = (socklen_t)sizeof addr;
+    socklen_t len0 = len;
 
     GetOpenFile(sock, fptr);
 
     if (getsockname(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
 	rb_sys_fail("getsockname(2)");
+    if (len0 < len) len = len0;
     return rsock_unixaddr(&addr, len);
 }
 
@@ -450,11 +454,13 @@ unix_peeraddr(VALUE sock) https://github.com/ruby/ruby/blob/trunk/ext/socket/unixsocket.c#L454
     rb_io_t *fptr;
     struct sockaddr_un addr;
     socklen_t len = (socklen_t)sizeof addr;
+    socklen_t len0 = len;
 
     GetOpenFile(sock, fptr);
 
     if (getpeername(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
 	rb_sys_fail("getpeername(2)");
+    if (len0 < len) len = len0;
     return rsock_unixaddr(&addr, len);
 }
 

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

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