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

Rust crate returns arbitrary numeric error codes instead of Result instances in some cases #224

Open
rcoder opened this issue Jun 6, 2023 · 0 comments

Comments

@rcoder
Copy link
Contributor

rcoder commented Jun 6, 2023

There are places in the current Rust bindings where the FFI glue wraps underlying C++ function calls in unsafe blocks, then casts the response to an expected type, ignoring potential error codes from the original API.

Example:

pub fn send_msg(&self, msg: &mut zts_msghdr) -> io::Result<usize> {

This example neither checks the global errno value, nor that the return value of the underlying C++ method is negative, which means that calls that error simply return the result of a (bogus) i32 -> usize cast.

We should audit this interface and look for cases where we're potentially doing unchecked casts, minimize use of unsafe, and (eventually) separate the low-level FFI into a dedicated libzt-sys crate with a safe, hardened Rust interface in this library.

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