Skip to content

use-after-free in proc_macro handle #56420

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

Closed
gobanos opened this issue Dec 1, 2018 · 2 comments
Closed

use-after-free in proc_macro handle #56420

gobanos opened this issue Dec 1, 2018 · 2 comments

Comments

@gobanos
Copy link

gobanos commented Dec 1, 2018

I'm the author of a proc_macro crate : https://github.com/gobanos/aoc-runner-derive, where I store syn::Ident & Box<syn::Type> in a thread_local HashMap.
When I retrieve data from another proc_macro handle, an use-after-free error occur.

I tried this code:

#[aoc_generator(...)] // <- store name & output type in a map
fn gen(input: &str) -> Vec<i32> {
    ...
}

#[aoc(...)] // <- retrieve them from the map
fn run(input: &[i32]) -> i32 {
    ...
}

Meta

rustc --version --verbose:
rustc 1.32.0-nightly (d09466c 2018-11-30)
binary: rustc
commit-hash: d09466c
commit-date: 2018-11-30
host: x86_64-unknown-linux-gnu
release: 1.32.0-nightly
LLVM version: 8.0

PS: was working find few days ago :
rustc 1.32.0-nightly (edaac35 2018-11-24)
binary: rustc
commit-hash: edaac35
commit-date: 2018-11-24
host: x86_64-unknown-linux-gnu
release: 1.32.0-nightly
LLVM version: 8.0

@kevinmehall
Copy link
Contributor

Macros aren't allowed to maintain state between calls.

Given that you're not using unsafe, it probably shouldn't allow a use-after-free, though. #56058 is about preventing the use of thread local storage.

@gobanos
Copy link
Author

gobanos commented Dec 1, 2018

Ok, so I should find a way to serialize data between calls.

I think it should be a compile time error, if possible.

Thanks for your time !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants