mirror of
https://github.com/ruby/ruby.git
synced 2025-08-25 22:14:37 +02:00
merge revision(s) r45045,r45046,r45530: [Backport #9697]
* ext/socket/ipsocket.c (ip_s_getaddress): Don't access freed memory. * ext/socket: Wrap struct addrinfo by struct rb_addrinfo. * ext/socket/socket.c (sock_s_getnameinfo): Save errno for EAI_SYSTEM. Reported by Saravana kumar. [ruby-core:61820] [Bug #9697] Fixed by Heesob Park. [ruby-core:61868] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@46054 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a3d95003e1
commit
e60ec9551c
7 changed files with 123 additions and 80 deletions
|
@ -44,7 +44,7 @@ udp_init(int argc, VALUE *argv, VALUE sock)
|
|||
|
||||
struct udp_arg
|
||||
{
|
||||
struct addrinfo *res;
|
||||
struct rb_addrinfo *res;
|
||||
int fd;
|
||||
};
|
||||
|
||||
|
@ -54,7 +54,7 @@ udp_connect_internal(struct udp_arg *arg)
|
|||
int fd = arg->fd;
|
||||
struct addrinfo *res;
|
||||
|
||||
for (res = arg->res; res; res = res->ai_next) {
|
||||
for (res = arg->res->ai; res; res = res->ai_next) {
|
||||
if (rsock_connect(fd, res->ai_addr, res->ai_addrlen, 0) >= 0) {
|
||||
return Qtrue;
|
||||
}
|
||||
|
@ -62,8 +62,6 @@ udp_connect_internal(struct udp_arg *arg)
|
|||
return Qfalse;
|
||||
}
|
||||
|
||||
VALUE rsock_freeaddrinfo(struct addrinfo *addr);
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* udpsocket.connect(host, port) => 0
|
||||
|
@ -113,19 +111,20 @@ static VALUE
|
|||
udp_bind(VALUE sock, VALUE host, VALUE port)
|
||||
{
|
||||
rb_io_t *fptr;
|
||||
struct addrinfo *res0, *res;
|
||||
struct rb_addrinfo *res0;
|
||||
struct addrinfo *res;
|
||||
|
||||
rb_secure(3);
|
||||
res0 = rsock_addrinfo(host, port, SOCK_DGRAM, 0);
|
||||
GetOpenFile(sock, fptr);
|
||||
for (res = res0; res; res = res->ai_next) {
|
||||
for (res = res0->ai; res; res = res->ai_next) {
|
||||
if (bind(fptr->fd, res->ai_addr, res->ai_addrlen) < 0) {
|
||||
continue;
|
||||
}
|
||||
freeaddrinfo(res0);
|
||||
rb_freeaddrinfo(res0);
|
||||
return INT2FIX(0);
|
||||
}
|
||||
freeaddrinfo(res0);
|
||||
rb_freeaddrinfo(res0);
|
||||
|
||||
rsock_sys_fail_host_port("bind(2)", host, port);
|
||||
|
||||
|
@ -160,7 +159,8 @@ udp_send(int argc, VALUE *argv, VALUE sock)
|
|||
VALUE flags, host, port;
|
||||
rb_io_t *fptr;
|
||||
int n;
|
||||
struct addrinfo *res0, *res;
|
||||
struct rb_addrinfo *res0;
|
||||
struct addrinfo *res;
|
||||
struct rsock_send_arg arg;
|
||||
|
||||
if (argc == 2 || argc == 3) {
|
||||
|
@ -173,21 +173,21 @@ udp_send(int argc, VALUE *argv, VALUE sock)
|
|||
GetOpenFile(sock, fptr);
|
||||
arg.fd = fptr->fd;
|
||||
arg.flags = NUM2INT(flags);
|
||||
for (res = res0; res; res = res->ai_next) {
|
||||
for (res = res0->ai; res; res = res->ai_next) {
|
||||
retry:
|
||||
arg.to = res->ai_addr;
|
||||
arg.tolen = res->ai_addrlen;
|
||||
rb_thread_fd_writable(arg.fd);
|
||||
n = (int)BLOCKING_REGION_FD(rsock_sendto_blocking, &arg);
|
||||
if (n >= 0) {
|
||||
freeaddrinfo(res0);
|
||||
rb_freeaddrinfo(res0);
|
||||
return INT2FIX(n);
|
||||
}
|
||||
if (rb_io_wait_writable(fptr->fd)) {
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
freeaddrinfo(res0);
|
||||
rb_freeaddrinfo(res0);
|
||||
rsock_sys_fail_host_port("sendto(2)", host, port);
|
||||
return INT2FIX(n);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue