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

refactor(es/parser): Don't attempt to handle shebangs in read_token_number_sign #7803

Merged
merged 1 commit into from
Aug 14, 2023

Conversation

Manishearth
Copy link
Contributor

@Manishearth Manishearth commented Aug 12, 2023

bump() has a safety invariant that there must be input in the buffer to read (See #7709).

This function as currently written calls bump() after calling read_token_interpreter(), which may have exhausted the buffer already in the specific case that it is handling a shebang. (The input string #!/bin/js with no newline is sufficient to cause UB here)

Fortunately, shebangs never reach this function, due to read_shebang! Hurray!

It's cleaner to not attempt to handle shebangs here when this code path will never be reached, and use a debug assertion to ensure that we're not dealing with shebangs.

@kdy1 kdy1 changed the title Don't attempt to handle shebangs in read_token_number_sign refactor(es/parser): Don't attempt to handle shebangs in read_token_number_sign Aug 14, 2023
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!


swc-bump:

  • swc_ecma_parser

@kdy1 kdy1 added this to the Planned milestone Aug 14, 2023
@kdy1 kdy1 enabled auto-merge (squash) August 14, 2023 01:33
@kdy1 kdy1 merged commit 5e7834a into swc-project:main Aug 14, 2023
128 checks passed
kdy1 pushed a commit to kdy1/swc that referenced this pull request Aug 15, 2023
…number_sign` (swc-project#7803)

bump() has a safety invariant that there must be input in the buffer to
read (See swc-project#7709).

This function as currently written calls `bump()` after calling
`read_token_interpreter()`, which *may* have exhausted the buffer
already in the specific case that it is handling a shebang. (The input
string `#!/bin/js` with no newline is sufficient to cause UB here)

Fortunately, shebangs never reach this function, due to `read_shebang`!
Hurray!

It's cleaner to not attempt to handle shebangs here when this code path
will never be reached, and use a debug assertion to ensure that we're
not dealing with shebangs.
@swc-project swc-project locked as resolved and limited conversation to collaborators Sep 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants