Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upSegfault due to using return pointer directly #34592
Comments
alexcrichton
added
I-nominated
T-compiler
labels
Jun 30, 2016
alexcrichton
added
the
A-codegen
label
Jun 30, 2016
This comment has been minimized.
This comment has been minimized.
|
Oh also worth pointing out that this is only a problem for old trans, MIR trans does not exhibit this segfault. |
arielb1
added
the
I-wrong
label
Jul 1, 2016
This comment has been minimized.
This comment has been minimized.
|
trans has way too many of these bugs, but we are moving to MIR-by-default soon anyway. |
luqmana
self-assigned this
Jul 5, 2016
This comment has been minimized.
This comment has been minimized.
|
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. |
luqmana
referenced this issue
Jul 5, 2016
Merged
Just pass in NodeId to FunctionContext::new instead of looking it up. #34658
bors
added a commit
that referenced
this issue
Jul 7, 2016
bors
added a commit
that referenced
this issue
Jul 7, 2016
bors
closed this
in
#34658
Jul 7, 2016
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
@posborne sure! I've nominated the PR for a beta backport at #34658 (comment) |
alexcrichton commentedJun 30, 2016
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:
decodefunction is called,read_structis called, then the closure is called.read_struct_fieldsucceeds, so the string is stored in theidfield directly into the return pointerread_struct_fieldfails, returning an errorErr(D::Error)) into the return pointeridBasically 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