-
Notifications
You must be signed in to change notification settings - Fork 0
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
[SECURITY] Quick review of the crate #1
Comments
Hi. Thanks a lot for looking at this! The memory thing is pretty embarrassing. I yanked the affected crates and fixed the issue, I think. I added your code as an integration test - hope that's okay! I'll keep this issue around as a TODO for generics. |
serde_json::from_str::<S>(&serde_json::to_string(&S { arr_big }).unwrap()).unwrap(); I couldn't trigger any problems since the memory was 0 initialized. You should check the code with miri. It can warn you about undefined behavior and leaked memory. I am pretty sure the new code now leaks memory during errors, for example with |
Does this basically illustrate your point about leaked memory? use std::mem::MaybeUninit;
struct Foo(String);
impl Foo {
fn new(s: impl ToString) -> Self {
Foo(s.to_string())
}
}
impl Drop for Foo {
fn drop(&mut self) {
println!("dropping {}", self.0);
}
}
fn main() {
{
let mut foos: [MaybeUninit<Foo>; 5] = unsafe { MaybeUninit::uninit().assume_init() };
for (i, e) in foos.iter_mut().enumerate().take(3) {
*e = MaybeUninit::new(Foo::new(i));
}
// Now we have a partially initialized array, but elements are still in MaybeUninits.
}
// No "droppping ..." prints for the foos we did initialize! Oops.
println!("Reached!");
} I wonder if I could do some magic before returning the error to I'm tempted to rewrite the whole thing without |
...or I could just learn from you, @jonasbb |
Yes that shows the leaked memory problem. You are welcome to look at or copy from |
Hi, in dtolnay/request-for-implementation#17 (comment) you asked for some feedback.
f1()
in this code just shows how generics currently do not work.f2()
however is a big security risk. Your array initialization is undefined behavior.Given that the crate is used by at least one other crate you should consider yanking all affected crates. You can do that via the
command line
or via theweb interface
.Adding a rustsec advisory might be a good option too.
The text was updated successfully, but these errors were encountered: