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

[[FIX]] Avoid crash when peeking past end of prog #2937

Merged
merged 1 commit into from
Aug 7, 2016

Conversation

jugglinmike
Copy link
Member

The lexer returns null values when tokens are requested after all
input has been consumed. Previously, the peek function would correctly
produce the special "(end)" token in situations where the parser
attempted to look beyond the end of the program. In such cases, however,
it would also pollute the lookahead buffer with an invalid entry--the
null value returned by the lexer. Future calls to peek could receive
this buffered value.

Because JSHint's internals are written with the assumption that peek
always returns a token object, the null value would trigger a
TypeError and subsequent program crash.

Re-factor the peek function to only insert valid token objects into
the lookahead buffer.

The lexer returns `null` values when tokens are requested after all
input has been consumed. Previously, the `peek` function would correctly
produce the special "(end)" token in situations where the parser
attempted to look beyond the end of the program. In such cases, however,
it would also pollute the lookahead buffer with an invalid entry--the
`null` value returned by the lexer. Future calls to `peek` could receive
this buffered value.

Because JSHint's internals are written with the assumption that `peek`
always returns a token object, the `null` value would trigger a
TypeError and subsequent program crash.

Re-factor the `peek` function to only insert valid token objects into
the lookahead buffer.
@jugglinmike
Copy link
Member Author

This ought to resolve gh-2932.

@rwaldron and/or @caitp: would you mind merging this if it looks good to you?

@coveralls
Copy link

coveralls commented Jun 4, 2016

Coverage Status

Coverage increased (+0.02%) to 97.674% when pulling cfe3e41 on jugglinmike:2932-peek-exhausted into 78cf7c1 on jshint:master.

t = lex.token();

// Peeking past the end of the program should produce the "(end)" token
// and should not extend the lookahead buffer.
Copy link
Member

Choose a reason for hiding this comment

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

Appreciate the explanation here

Copy link
Member Author

Choose a reason for hiding this comment

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

:)

@rwaldron rwaldron merged commit 330d429 into jshint:master Aug 7, 2016
jugglinmike added a commit to jugglinmike/jshint that referenced this pull request Sep 4, 2016
The lexer returns `null` values when tokens are requested after all
input has been consumed. Previously, the `peek` function would correctly
produce the special "(end)" token in situations where the parser
attempted to look beyond the end of the program. In such cases, however,
it would also pollute the lookahead buffer with an invalid entry--the
`null` value returned by the lexer. Future calls to `peek` could receive
this buffered value.

Because JSHint's internals are written with the assumption that `peek`
always returns a token object, the `null` value would trigger a
TypeError and subsequent program crash.

Re-factor the `peek` function to only insert valid token objects into
the lookahead buffer.
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.

None yet

3 participants