Skip to content

Correctly handle libuv errors in addrinfo calls #10664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/librustuv/addrinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@ pub fn accum_addrinfo(addr: &Addrinfo) -> ~[ai::Info] {
}
}

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

#[test]
#[ignore(cfg(target_os="android"))] // cannot give tcp/ip permission without help of apk
fn getaddrinfo_test() {
match GetAddrInfoRequest::run(local_loop(), Some("localhost"), None, None) {
Ok(infos) => {
Expand All @@ -208,4 +208,12 @@ mod test {
Err(e) => fail!("{:?}", e),
}
}

#[test]
fn issue_10663() {
// Something should happen here, but this certainly shouldn't cause
// everything to die. The actual outcome we don't care too much about.
GetAddrInfoRequest::run(local_loop(), Some("irc.n0v4.com"), None,
None);
}
}
11 changes: 8 additions & 3 deletions src/librustuv/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,17 @@ pub fn sockaddr_to_socket_addr(addr: *sockaddr) -> SocketAddr {
fail!("unknown address?");
};
let ip_name = {
// apparently there's an off-by-one in libuv?
let ip_size = ip_size + 1;
let buf = vec::from_elem(ip_size + 1 /*null terminated*/, 0u8);
let buf_ptr = vec::raw::to_ptr(buf);
if uvll::rust_is_ipv4_sockaddr(addr) == 1 {
uvll::uv_ip4_name(addr, buf_ptr as *c_char, ip_size as size_t);
let ret = if uvll::rust_is_ipv4_sockaddr(addr) == 1 {
uvll::uv_ip4_name(addr, buf_ptr as *c_char, ip_size as size_t)
} else {
uvll::uv_ip6_name(addr, buf_ptr as *c_char, ip_size as size_t);
uvll::uv_ip6_name(addr, buf_ptr as *c_char, ip_size as size_t)
};
if ret != 0 {
fail!("error parsing sockaddr: {}", UvError(ret).desc());
}
buf
};
Expand Down