Skip to content

From impls that take libc types are unsound #1977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
djkoloski opened this issue Jan 24, 2023 · 0 comments
Open

From impls that take libc types are unsound #1977

djkoloski opened this issue Jan 24, 2023 · 0 comments

Comments

@djkoloski
Copy link
Contributor

User and Group implement From<libc::passwd> and From<libc::group>, but these structs contain public fields which are pointers and are not guaranteed to uphold the invariants guaranteed after fetching with functions like getpw* and getgr*. These functions should be unsafe with the requirement that the passed struct is the output from one of these functions. For example:

impl User {
    /// # Safety
    ///
    /// `passwd` must be the output from some `getpw*` call, like `getpwuid`.
    unsafe fn from_passwd(passwd: &libc::passwd) -> Self {
        ...
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant