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

use-after-free in `proc_macro` handle #56420

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

Comments

Projects
None yet
2 participants
@gobanos

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

This comment has been minimized.

Contributor

kevinmehall commented Dec 1, 2018

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

This comment has been minimized.

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 !

@gobanos gobanos closed this Dec 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment