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

Public API of bp7 exposes UB to safe code #2

Closed
dtolnay opened this issue Sep 19, 2021 · 1 comment
Closed

Public API of bp7 exposes UB to safe code #2

dtolnay opened this issue Sep 19, 2021 · 1 comment

Comments

@dtolnay
Copy link

dtolnay commented Sep 19, 2021

For example, the following safe program leads to bp7 performing Undefined Behavior:

// [dependencies]
// bp7 = "0.9.2"

fn main() {
    bp7::ffi::bundle_payload(0xdeadbeefusize as _);
}
Segmentation fault (core dumped)

In general it is unsound for a safe API to result in UB.

@gh0st42
Copy link
Member

gh0st42 commented Sep 27, 2021

Thank you for pointing this out!

I experimented with different alternatives but would would you suggest as the cleanest solution?

As a rust crate the whole FFI module is not needed and should not be used.
To create the headers using cbindgen the mentioned function must be made public.
Thus, it appears also in the rust crate.

Gating it behind a feature flag makes it a bit harder to accidentally misuse it but in the end the UB could still end up in rust code.

Adding unsafe to all functions pleases clippy but should not extern "C" already imply that it is unsafe or contains potential UB?

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

2 participants