Skip to content

Commit e03f17e

Browse files
committed
auto merge of #10664 : alexcrichton/rust/issue-10663, r=luqmana
It turns out that libuv was returning ENOSPC to us in our usage of the uv_ipX_name functions. It also turns out that there may be an off-by-one in libuv. For now just add one to the buffer size and handle the return value correctly. Closes #10663
2 parents ef70b76 + 7f35012 commit e03f17e

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/librustuv/addrinfo.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ pub fn accum_addrinfo(addr: &Addrinfo) -> ~[ai::Info] {
184184
}
185185
}
186186

187-
#[cfg(test)]
187+
// cannot give tcp/ip permission without help of apk
188+
#[cfg(test, not(target_os="android"))]
188189
mod test {
189190
use std::io::net::ip::{SocketAddr, Ipv4Addr};
190191
use super::*;
191192
use super::super::local_loop;
192193

193194
#[test]
194-
#[ignore(cfg(target_os="android"))] // cannot give tcp/ip permission without help of apk
195195
fn getaddrinfo_test() {
196196
match GetAddrInfoRequest::run(local_loop(), Some("localhost"), None, None) {
197197
Ok(infos) => {
@@ -208,4 +208,12 @@ mod test {
208208
Err(e) => fail!("{:?}", e),
209209
}
210210
}
211+
212+
#[test]
213+
fn issue_10663() {
214+
// Something should happen here, but this certainly shouldn't cause
215+
// everything to die. The actual outcome we don't care too much about.
216+
GetAddrInfoRequest::run(local_loop(), Some("irc.n0v4.com"), None,
217+
None);
218+
}
211219
}

src/librustuv/net.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,17 @@ pub fn sockaddr_to_socket_addr(addr: *sockaddr) -> SocketAddr {
5959
fail!("unknown address?");
6060
};
6161
let ip_name = {
62+
// apparently there's an off-by-one in libuv?
63+
let ip_size = ip_size + 1;
6264
let buf = vec::from_elem(ip_size + 1 /*null terminated*/, 0u8);
6365
let buf_ptr = vec::raw::to_ptr(buf);
64-
if uvll::rust_is_ipv4_sockaddr(addr) == 1 {
65-
uvll::uv_ip4_name(addr, buf_ptr as *c_char, ip_size as size_t);
66+
let ret = if uvll::rust_is_ipv4_sockaddr(addr) == 1 {
67+
uvll::uv_ip4_name(addr, buf_ptr as *c_char, ip_size as size_t)
6668
} else {
67-
uvll::uv_ip6_name(addr, buf_ptr as *c_char, ip_size as size_t);
69+
uvll::uv_ip6_name(addr, buf_ptr as *c_char, ip_size as size_t)
70+
};
71+
if ret != 0 {
72+
fail!("error parsing sockaddr: {}", UvError(ret).desc());
6873
}
6974
buf
7075
};

0 commit comments

Comments
 (0)