Skip to content
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
11 changes: 7 additions & 4 deletions rules/socket/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,20 @@ impl Sockaddr {
.with_slice_mut(len, |buf| buf.copy_from_slice(&bytes[..len]));
}
};
match ss.family() {
let len = match ss.family() {
Some(AddressFamily::Inet) => {
let l = ::libc::sockaddr_in::from(*ss.as_sockaddr_in().unwrap());
let mut bytes = [0; ::std::mem::size_of::<::libc::sockaddr_in>()];
SockaddrIn::from_libc(&l).to_bytes(&mut bytes);
write(&bytes);
::std::mem::size_of_val(&l) as u32
}
Some(AddressFamily::Inet6) => {
let l = ::libc::sockaddr_in6::from(*ss.as_sockaddr_in6().unwrap());
let mut bytes = [0; ::std::mem::size_of::<::libc::sockaddr_in6>()];
SockaddrIn6::from_libc(&l).to_bytes(&mut bytes);
write(&bytes);
::std::mem::size_of_val(&l) as u32
}
Some(AddressFamily::Unix) => {
if let Some(addr) = ss.as_unix_addr() {
Expand All @@ -281,10 +283,11 @@ impl Sockaddr {
});
}
}
ss.len()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should return len here, I believe

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local len is the truncated copy count, not the address length. POSIX says, “The address_len argument points to a socklen_t object which on input specifies the length of the supplied sockaddr structure, and on output specifies the length of the socket address.” The native C checks in tests/unit/socket_unix_name.c pass with zero and short buffers while requiring the full returned length, so ss.len() is retained.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then it should be something like ::std::mem::size_of_val(&l) as u32. I think ss.len() doesn't make sense

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux, native and translated return 19 for the named socket and 2 for the unnamed one; size_of_val(&l) gives 8 because l is a reference, while size_of::<sockaddr_un>() gives 110. POSIX says, “The address_len argument points to a socklen_t object which on input specifies the length of the supplied sockaddr structure, and on output specifies the length of the socket address.” The updated tests/unit/socket_unix_name.c checks portable named and unnamed lengths and prints them for native-versus-translated comparison; do you still want size_of_val?

}
_ => {}
}
out_len.write(ss.len());
_ => panic!("unsupported socket address family"),
};
out_len.write(len);
}
}

Expand Down
6 changes: 5 additions & 1 deletion rules/socket/tgt_refcount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ fn f17(a0: i32, a1: AnyPtr, a2: usize, a3: i32, a4: Ptr<Sockaddr>, a5: Ptr<u32>)
}) {
Ok((__n, __from)) => {
match __from {
Some(__ss) => Sockaddr::encode(&__ss, &a4, &a5),
Some(__ss) => {
if !a4.is_null() {
Sockaddr::encode(&__ss, &a4, &a5)
}
}
None => {}
}
__n as isize
Expand Down
Loading
Loading