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

Can access invalid memory and cause sigsegv using safe Rust #31852

Closed
ruuda opened this issue Feb 23, 2016 · 5 comments
Closed

Can access invalid memory and cause sigsegv using safe Rust #31852

ruuda opened this issue Feb 23, 2016 · 5 comments
Labels
T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ruuda
Copy link
Contributor

ruuda commented Feb 23, 2016

When working on a crate I discovered the following issue. I did not succeed in making a minimal example that reproduces on play.rust-lang.org, so let me just link to the actual code:

Note how this prints the contents of some memory that the function shouldn’t be able to access, and then terminates with sigsegv.

An observation: with reexports it is possible to reexport a type on which a method is defined that returns a type that is not reexported. In a sense this allows returning anonymous types. In the documentation these types are named but they do not link to a documentation page, and if you name them explicitly the compiler complains because they are not public. I am not sure whether this is a bug or feature.

Related (what initially made me suspicious): this function mutates a variable that was borrowed mutably by a closure.

@ruuda
Copy link
Contributor Author

ruuda commented Feb 23, 2016

Oh, and rustc version: rustc 1.8.0-nightly (75271d8f1 2016-02-09). I updated to rustc 1.8.0-nightly (c8fc4817d 2016-02-22) and the issue is still present.

@alexcrichton
Copy link
Member

After reducing this, it looks like the bug is that the compiler accepts this:

trait Foo {                          
    fn foo<T>(&self, t: T);          
}                                    

impl Foo for i32 {                   
    fn foo<T: 'static>(&self, t: T) {
    }                                
}                                    

fn foo(a: i32, not_static: &i32) {   
    a.foo(not_static);               
}                                    

The i32 implementation is allowed to assume it's only given 'static content, when in fact we can feed in anything!

@alexcrichton
Copy link
Member

In your code specifically @ruud-v-a the Observable::subscribe method requires just an O parameter whereas SubjectObservable::subscribe adds on 'static

@alexcrichton
Copy link
Member

triage: I-nominated

This seems familiar as in we've had it reported before, but... I thought we fixed it with a bunch of well-formededness RFCs? Seems good to get visibility though!

cc @rust-lang/compiler

@alexcrichton alexcrichton added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 23, 2016
@alexcrichton
Copy link
Member

Aha! and @nikomatsakis pointed out on IRC that this is #18937, so I'll just close in favor of that. Thanks for the report though @ruud-v-a!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants