diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-07-17 22:26:39 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-17 22:26:39 +0000 |
commit | c375a102ac0af0d08c4942ffd81c84b6d6769d08 (patch) | |
tree | 6ebde1ce38d1646e0d1be66b5bfa09d1bd9530a6 /test/sys/mod.rs | |
parent | 1d61638a72d91e5a5df03da4ab83182352a4d8e4 (diff) | |
parent | 2d60044196bbcf6c4da187f413e7ddd00f0a2ae0 (diff) | |
download | nix-c375a102ac0af0d08c4942ffd81c84b6d6769d08.zip |
Merge #2041master
2041: Set the length of a socket address when calling `recvmsg` on Linux r=asomers a=JarredAllen
# Background
I think I've found a bug with `recvmsg` on Linux where it doesn't set the length of a received socket address. I found this while working with unix datagram sockets with path `struct sockaddr_un` addresses, but I think this applies to any variable-length socket address type.
At present, the `sun_len` field of `UnixAddr` on Linux shows up as 0 whenever I call `recvmsg`. I think it's reading uninitialized memory (afaict the `recvmsg` function never initializes it before we call `MaybeUninit::assume_init`), though it's possible that it's being zero-initialized somewhere that I missed. Either way, this isn't the correct behavior, which should set it to the length of the `struct sockaddr_un` contents (or whatever other type of socket).
# Changes
I changed the `recvmsg` function to construct the returned socket address from the `struct sockaddr` and length returned by the libc `recvmsg` call (using the `from_raw` function the trait provides). Since the trait is sealed so downstream crates can't implement it, I believe this shouldn't be a breaking change.
# Validation
I've tested that my code (which failed due to this bug) now works. I also added a new test case which tests that we construct `UnixAddr`s correctly in the `recvmsg` function, which passes locally for me and fails if I cherry-pick it onto the current `master`.
I've also checked that `cargo test` and `cargo clippy` both still pass on `aarch64-apple-darwin` and on `aarch64-unknown-linux-musl` targets (the two targets I develop for/have access to). Hopefully your CI will confirm that everything else still works.
Co-authored-by: Jarred Allen <jarred@moveparallel.com>
Co-authored-by: Jarred Allen <jarredallen73@gmail.com>
Diffstat (limited to 'test/sys/mod.rs')
0 files changed, 0 insertions, 0 deletions