-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Segfault due to using return pointer directly #34592
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
Comments
Oh also worth pointing out that this is only a problem for old trans, MIR trans does not exhibit this segfault. |
trans has way too many of these bugs, but we are moving to MIR-by-default soon anyway. |
Here is a smaller test case. Seems like it has to be a nested return in a closure in a generic cross crate fn. pub struct Request {
pub id: String,
pub arg: String,
}
pub fn decode<T>() -> Result<Request, ()> {
(|| {
Ok(Request {
id: "hi".to_owned(),
arg: match Err(()) {
Ok(v) => v,
Err(e) => return Err(e)
},
})
})()
} extern crate test;
fn main() {
assert!(test::decode::<()>().is_err());
} I think I have a fix for it and I'll try to put it up soon. |
Just pass in NodeId to FunctionContext::new instead of looking it up. Fixes #34592.
@alexcrichton I'm running into this on 1.10 and it also fails on This bug would seems to breaks the canonical way of doing JSON parsing for the majority of users. |
@posborne sure! I've nominated the PR for a beta backport at #34658 (comment) |
First reported at rust-lang-deprecated/rustc-serialize#154, it looks like the code in that issue will segfault on all platforms and isn't related to the allocator in question, it's just a bad free. It looks like the expansion of
#[derive(RustcDecodable)]
is the function that's segfaulting, specifically:In this function the closure should detect that it has nested returns and therefore the closure should write intermediate results into a local alloca of what to return. Instead, though, no alloca is created an results are stored directly into the return pointer.
The fault looks like it happens when:
decode
function is called,read_struct
is called, then the closure is called.read_struct_field
succeeds, so the string is stored in theid
field directly into the return pointerread_struct_field
fails, returning an errorErr(D::Error)
) into the return pointerid
Basically at that point it's freeing arbitrary data because the string has already been paved over. I have been unable to reproduce this with a smaller example because everything I do seems to trigger usage of an alloca for the return value (which should be happening here). Maybe someone else knows though how to trigger this with a smaller example.
In any case though this segafult happens on nightly/beta/stable, but would be very good to fix!
cc @rust-lang/compiler
also nominating
The text was updated successfully, but these errors were encountered: