Skip to content
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

macos' get_os_release leaks and misbehaves #97

Open
steven-joruk opened this issue Jun 8, 2021 · 0 comments
Open

macos' get_os_release leaks and misbehaves #97

steven-joruk opened this issue Jun 8, 2021 · 0 comments

Comments

@steven-joruk
Copy link

The get_os_release C function allocates the buffer on the heap and returns it, but on the rust side it doesn't take ownership of the memory:

buf = malloc(LEN);
let typ = ffi::CStr::from_ptr(rp).to_bytes();

Also, if an error occurs on the C side it uses strncpy to set it to "Unknown", but on rust's side it expects a NULL pointer to be returned in case of error:

// At this point `len` is _most likely_ set to `0` (e.g. in case of ENOMEM).
// We copy our string and reset the length.
strncpy(buf, "Unknown", LEN);
if rp == std::ptr::null() {
    Err(Error::Unknown)
}

There are other heap allocations on the C side I haven't verified are handled correctly on rust's side.

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