summaryrefslogtreecommitdiff
path: root/ext/socket/basicsocket.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-30 12:01:51 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-30 12:01:51 +0000
commit1ff38a5bbf2baa5fa6646fffdc81ed3611be805b (patch)
treeb87a16f878ac955f6a23011223f596170441b9d9 /ext/socket/basicsocket.c
parent111b86142280d3257021d142fce1317b44c1b850 (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38993 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/basicsocket.c')
-rw-r--r--ext/socket/basicsocket.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/ext/socket/basicsocket.c b/ext/socket/basicsocket.c
index c1ae88d..2ef4f32 100644
--- a/ext/socket/basicsocket.c
+++ b/ext/socket/basicsocket.c
@@ -358,11 +358,13 @@ bsock_getsockname(VALUE sock)
{
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)
{
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)
{
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)
{
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);
}