1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/socket/ipsocket.c (ip_s_getaddress): Don't access freed memory.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45045 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2014-02-19 08:51:33 +00:00
parent 2c36345ad6
commit 948ce9decb
2 changed files with 7 additions and 2 deletions

View file

@ -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