Fix Clippy warnings on FreeBSD with the latest nightly#1639
Fix Clippy warnings on FreeBSD with the latest nightly#1639bors[bot] merged 2 commits intonix-rust:masterfrom
Conversation
asomers
commented
Jan 22, 2022
- Better type safety for mqueue
- Suppress clippy::not_unsafe_ptr_arg_deref warnings in ptrace on BSD
On some platforms, mqd_t is a pointer. That means code like the below
can trigger a segfault. Fix it by defining a Newtype around mqd_t that
prevents use-after-free and dangling pointer scenarios.
```rust
fn invalid_mqd_t() {
let mqd: libc::mqd_t = std::ptr::null_mut();
mq_close(mqd).unwrap();
}
```
Also, get test coverage for mqueue in CI on FreeBSD.
Technically these functions don't violate Rust's safety rules, because libc::ptrace doesn't dereference those pointer args. Instead, it passes them directly to the kernel.
|
Supersedes #1638 |
|
bors r+ |
|
POSIX does explicitly mention that |
|
@lucab could you give an example in Rust, C, or pseudocode? How would that feature work? |
|
Sure, and thanks for the prompt reply! |
I think it's worth noting that the conversion itself was infallible. You could end up with an invalid mqueue-descriptor, as
Implementing We should probably implement all four traits on Linux and any other platforms that use FDs instead of pointers for |