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

Field is_ok should be private for DiplomatResult #270

Open
imbrem opened this issue Oct 16, 2022 · 3 comments
Open

Field is_ok should be private for DiplomatResult #270

imbrem opened this issue Oct 16, 2022 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed techdebt Internal issue with minimal external impact

Comments

@imbrem
Copy link

imbrem commented Oct 16, 2022

Since is_ok is public, it is trivial to get UB in Safe Rust using Diplomat (without any FFI) by writing

let rust_result: Result<u64, Box<u64>> = Ok(32);
let mut result: DiplomatResult<u64, Box<u64>> = rust_result.into();
result.is_ok = false;
std::mem::drop(result);

This will attempt to call Box::drop on the value 32, leading to a segmentation fault.

One can retain about equivalent API power (since is_ok is the only public field) by having a safe getter returning the value and an unsafe getter returning a mutable reference to the value.

@Manishearth
Copy link
Contributor

Yeah, makes sense. The diplomat_runtime crate is basically supposed to be used in certain ways so we haven't tried to guard it against things like this, but this seems reasonable enough to do.

@imbrem
Copy link
Author

imbrem commented Oct 17, 2022

Want me to submit a PR? I'm also willing to have a read through for some more UB, as I want to use this to do the FFI for a project I'll be doing as part of my PhD thesis which needs a good C++ interface. Not doing it right away as it probably needs a version bump due to semver...

@Manishearth
Copy link
Contributor

Yeah go for it. I'm fine with breaking semver over soundness; people should not have been using the is_ok field anyway.

As far as fixing everything, an audit would be great, but we probably won't fix everything.

Since it lives on the FFI boundary there probably a lot of soundness issues inherent to the design that we won't fix (since they will be hard to trigger unintentionally)

In particular, currently we let you violate single-mutable-reference rules in a way that's relatively benign as long as you design your diplomat APIs carefully. We do have a plan for fixing that (#225), if you follow the rules set out there it should be fine.

Alspo happy to answer questions as you're using it. We haven't documented this that well (and have some major improvements in the pipeline) so you might have more questions.

@Manishearth Manishearth added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed techdebt Internal issue with minimal external impact labels Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed techdebt Internal issue with minimal external impact
Projects
None yet
Development

No branches or pull requests

2 participants