HLE clears the result of blocked address lookups
(cherry picked from commit 2b13ae41920296be79dc9642913a7807ecc98d57)
This commit is contained in:
1 parent
b6ca1191b7
commit
2d34e466b3
1 file changed
+57
-4
@@ -537,6 +537,14 @@ pub extern "system" fn bind(s: Socket, name: *const u8, len: i32) -> i32 {
|
||||
|
||||
// Forward lookups.
|
||||
|
||||
fn blocked_lookup(result: *mut *mut c_void) -> i32 {
|
||||
if !result.is_null() {
|
||||
// SAFETY: a non-null result points to the caller's output slot.
|
||||
unsafe { result.write(std::ptr::null_mut()) };
|
||||
}
|
||||
WSAHOST_NOT_FOUND
|
||||
}
|
||||
|
||||
pub extern "system" fn getaddrinfo(
|
||||
node: *const c_char,
|
||||
service: *const c_char,
|
||||
@@ -544,7 +552,7 @@ pub extern "system" fn getaddrinfo(
|
||||
result: *mut *mut c_void,
|
||||
) -> i32 {
|
||||
if !resolvable(narrow(node)) {
|
||||
return WSAHOST_NOT_FOUND;
|
||||
return blocked_lookup(result);
|
||||
}
|
||||
host!("ws2_32.dll", "getaddrinfo": extern "system" fn(*const c_char, *const c_char, *const c_void, *mut *mut c_void) -> i32)(
|
||||
node, service, hints, result,
|
||||
@@ -558,7 +566,7 @@ pub extern "system" fn GetAddrInfoW(
|
||||
result: *mut *mut c_void,
|
||||
) -> i32 {
|
||||
if !resolvable(wide(node)) {
|
||||
return WSAHOST_NOT_FOUND;
|
||||
return blocked_lookup(result);
|
||||
}
|
||||
host!("ws2_32.dll", "GetAddrInfoW": extern "system" fn(*const u16, *const u16, *const c_void, *mut *mut c_void) -> i32)(
|
||||
node, service, hints, result,
|
||||
@@ -578,7 +586,7 @@ pub extern "system" fn GetAddrInfoExA(
|
||||
handle: *mut Handle,
|
||||
) -> i32 {
|
||||
if !resolvable(narrow(name)) {
|
||||
return WSAHOST_NOT_FOUND;
|
||||
return blocked_lookup(result);
|
||||
}
|
||||
host!("ws2_32.dll", "GetAddrInfoExA": extern "system" fn(*const c_char, *const c_char, u32, *const c_void, *const c_void, *mut *mut c_void, *const c_void, *mut c_void, *const c_void, *mut Handle) -> i32)(
|
||||
name, service, namespace, provider, hints, result, timeout, overlapped, completion, handle,
|
||||
@@ -598,7 +606,7 @@ pub extern "system" fn GetAddrInfoExW(
|
||||
handle: *mut Handle,
|
||||
) -> i32 {
|
||||
if !resolvable(wide(name)) {
|
||||
return WSAHOST_NOT_FOUND;
|
||||
return blocked_lookup(result);
|
||||
}
|
||||
host!("ws2_32.dll", "GetAddrInfoExW": extern "system" fn(*const u16, *const u16, u32, *const c_void, *const c_void, *mut *mut c_void, *const c_void, *mut c_void, *const c_void, *mut Handle) -> i32)(
|
||||
name, service, namespace, provider, hints, result, timeout, overlapped, completion, handle,
|
||||
@@ -895,6 +903,51 @@ mod tests {
|
||||
const AWAY: [u8; 4] = [192, 0, 2, 1];
|
||||
const HOME: [u8; 4] = [127, 0, 0, 1];
|
||||
|
||||
#[test]
|
||||
fn blocked_name_lookups_clear_the_result() {
|
||||
let ansi = c"blocked.invalid".as_ptr();
|
||||
let wide: Vec<u16> = "blocked.invalid\0".encode_utf16().collect();
|
||||
let wide = wide.as_ptr();
|
||||
let null = std::ptr::null();
|
||||
let null_mut = std::ptr::null_mut();
|
||||
let check = |lookup: &dyn Fn(*mut *mut c_void) -> i32| {
|
||||
let mut result = std::ptr::dangling_mut::<c_void>();
|
||||
assert_eq!(lookup(&mut result), WSAHOST_NOT_FOUND);
|
||||
assert!(result.is_null());
|
||||
assert_eq!(lookup(std::ptr::null_mut()), WSAHOST_NOT_FOUND);
|
||||
};
|
||||
check(&|result| getaddrinfo(ansi, std::ptr::null(), null, result));
|
||||
check(&|result| GetAddrInfoW(wide, std::ptr::null(), null, result));
|
||||
check(&|result| {
|
||||
GetAddrInfoExA(
|
||||
ansi,
|
||||
std::ptr::null(),
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
result,
|
||||
null,
|
||||
null_mut,
|
||||
null,
|
||||
std::ptr::null_mut(),
|
||||
)
|
||||
});
|
||||
check(&|result| {
|
||||
GetAddrInfoExW(
|
||||
wide,
|
||||
std::ptr::null(),
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
result,
|
||||
null,
|
||||
null_mut,
|
||||
null,
|
||||
std::ptr::null_mut(),
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_loopback_is_reachable() {
|
||||
// Also starts Winsock for the raw calls below.
|
||||
|
||||
Reference in new issue
Block a user