summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--ext/socket/ipsocket.c5
2 files changed, 7 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index e6e8ce9a9e6..190a6c8a29b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Wed Feb 19 17:47:01 2014 Tanaka Akira <akr@fsij.org>
+
+ * ext/socket/ipsocket.c (ip_s_getaddress): Don't access freed memory.
+
Wed Feb 19 11:39:41 2014 NARUSE, Yui <naruse@ruby-lang.org>
* configure.in: it must see rb_cv_broken_memmem not rb_cv_func_memmem.
diff --git a/ext/socket/ipsocket.c b/ext/socket/ipsocket.c
index 7b198bd1547..874c0da3e5a 100644
--- a/ext/socket/ipsocket.c
+++ b/ext/socket/ipsocket.c
@@ -305,12 +305,13 @@ ip_s_getaddress(VALUE obj, VALUE host)
{
union_sockaddr addr;
struct addrinfo *res = rsock_addrinfo(host, Qnil, SOCK_STREAM, 0);
+ socklen_t len = res->ai_addrlen;
/* just take the first one */
- memcpy(&addr, res->ai_addr, res->ai_addrlen);
+ memcpy(&addr, res->ai_addr, len);
freeaddrinfo(res);
- return rsock_make_ipaddr(&addr.addr, res->ai_addrlen);
+ return rsock_make_ipaddr(&addr.addr, len);
}
void