Skip to content

Commit

Permalink
Getaddrinfo bug (invalid mem::transmute) (#2305)
Browse files Browse the repository at this point in the history
* Fixed mem::transmute

* Changelog entry
  • Loading branch information
Razz4780 authored Mar 14, 2024
1 parent ed89787 commit 60968f6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/+getaddrinfo-hints-bug.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a bug with handling hints passed to `getaddrinfo` function.
5 changes: 3 additions & 2 deletions mirrord/layer/src/socket/hooks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::ffi::CString;
use core::{cmp, ffi::CStr, mem};
use core::{cmp, ffi::CStr};
use std::{os::unix::io::RawFd, sync::LazyLock};

use dashmap::DashSet;
Expand Down Expand Up @@ -263,8 +263,9 @@ unsafe extern "C" fn getaddrinfo_detour(
) -> c_int {
let rawish_node = (!raw_node.is_null()).then(|| CStr::from_ptr(raw_node));
let rawish_service = (!raw_service.is_null()).then(|| CStr::from_ptr(raw_service));
let rawish_hints = raw_hints.as_ref();

getaddrinfo(rawish_node, rawish_service, mem::transmute(raw_hints))
getaddrinfo(rawish_node, rawish_service, rawish_hints)
.map(|c_addr_info_ptr| {
out_addr_info.copy_from_nonoverlapping(&c_addr_info_ptr, 1);
MANAGED_ADDRINFO.insert(c_addr_info_ptr as usize);
Expand Down

0 comments on commit 60968f6

Please sign in to comment.