summaryrefslogtreecommitdiff
path: root/ext/socket/basicsocket.c
diff options
context:
space:
mode:
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 c1ae88d80cd..2ef4f32692a 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);
}