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

rustc: references can escape their lifetime via trait objects #14868

Closed
aturon opened this issue Jun 13, 2014 · 2 comments
Closed

rustc: references can escape their lifetime via trait objects #14868

aturon opened this issue Jun 13, 2014 · 2 comments
Labels
I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Comments

@aturon
Copy link
Member

aturon commented Jun 13, 2014

A trait impl on a reference can be used to violate lifetimes via trait objects. The following segfaults on my OSX machine:

trait Oops {
    fn expose<'b>(&'b self) -> &'b Vec<u8>;
}

impl<'a> Oops for &'a Vec<u8> {
    fn expose<'b>(&'b self) -> &'b Vec<u8> {
        *self
    }
}

fn hide(x: &Vec<u8>) -> Box<Oops> {
    box x as Box<Oops>
}

fn hidden_pointer_into_frame() -> Box<Oops> {
    let v = vec!(37);
    hide(&v)
}

fn main() {
    let hp: Box<Oops> = hidden_pointer_into_frame();
    let p: &Vec<u8> = hp.expose();
    println!("{}", *p)
}
@aturon
Copy link
Member Author

aturon commented Jun 13, 2014

Possibly an instance of #2203, but I'm not sure.

@aturon
Copy link
Member Author

aturon commented Jun 13, 2014

Actually, this is almost certainly a dupe of one of #11374, #5723, #11971 or #12781.

Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Projects
None yet
Development

No branches or pull requests

1 participant