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

Prevent ICE when calling parse_attribute without an attribute #5732

Merged
merged 1 commit into from
Jun 19, 2023

Conversation

ytmimi
Copy link
Contributor

@ytmimi ytmimi commented Apr 1, 2023

Fixes #5729

parse_attribute will panic if the first token is not a #. To prevent this we return early instead of trying to parse an invalid attribute.

@calebcartwright
Copy link
Member

I feel like this is probably a pebcak issue, but I'm puzzled why the change we're making is dealing with the first token following the keyword not being a # while our test input has # as the first token.

Am I misunderstanding and/or missing something obvious?

I would've thought the test input we'd use would include some non-# token in the first position, e.g. the input from the referenced issue:

cfg_if::cfg_if! {
    if {
    } else if #(&cpus) {
    } else [libc::CTL_HW, libc::HW_NCPU, 0, 0]
}

@ytmimi
Copy link
Contributor Author

ytmimi commented Apr 24, 2023

@calebcartwright Thank you for catching that. We should be using the snippet from the referenced issue.

While I was investigating what was going on I modified the snippet by adding the # just to see if that would prevent the ICE and accidentally committed that test case. Going to update it now.

Fixes 5729

`parse_attribute` will panic if the first token is not a `#`. To prevent
this we return early instead of trying to parse an invalid attribute.
@calebcartwright calebcartwright added the release-notes Needs an associated changelog entry label Jun 19, 2023
@calebcartwright calebcartwright merged commit ac2ebd3 into rust-lang:master Jun 19, 2023
@calebcartwright calebcartwright removed the release-notes Needs an associated changelog entry label Jun 20, 2023
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

Successfully merging this pull request may close these issues.

ICE parse_attribute called in non-attribute position
2 participants