Fix undefined behavior from front() on empty token deque in SquelchCombine parser - #807
Open
MarkRose wants to merge 1 commit into
Open
Fix undefined behavior from front() on empty token deque in SquelchCombine parser#807MarkRose wants to merge 1 commit into
MarkRose wants to merge 1 commit into
Conversation
…mbine parser The SQL_COMBINE expression parser in SquelchCombine.cpp called std::deque::front() on m_tokens without first checking that the deque was non-empty, which is undefined behavior (typically a crash) rather than a clean configuration error. - parseUnaryOpExpression() checked `m_tokens.front() == "!"` as its very first statement, before parseInstExpression()'s empty-deque guard ever runs. An empty or whitespace-only SQL_COMBINE value tokenizes to an empty deque, so this is hit immediately during initialize(). - parseInstExpression() checked `m_tokens.front() != ")"` after parsing a parenthesized sub-expression, without verifying a closing paren token still remained. An unbalanced-parenthesis expression such as "(a" leaves the deque empty at that point, triggering the same undefined behavior. Both call sites now go through a new local helper, tokenFrontIs(), that safely returns false when the deque is empty instead of dereferencing front(), so malformed SQL_COMBINE values are now rejected with the existing error-reporting/parse-failure path instead of crashing. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The SQL_COMBINE expression parser in SquelchCombine.cpp called
std::deque::front() on m_tokens without first checking that the deque was
non-empty, which is undefined behavior (typically a crash) rather than a
clean configuration error.
m_tokens.front() == "!"as its veryfirst statement, before parseInstExpression()'s empty-deque guard ever
runs. An empty or whitespace-only SQL_COMBINE value tokenizes to an empty
deque, so this is hit immediately during initialize().
m_tokens.front() != ")"after parsing aparenthesized sub-expression, without verifying a closing paren token
still remained. An unbalanced-parenthesis expression such as "(a" leaves
the deque empty at that point, triggering the same undefined behavior.
Both call sites now go through a new local helper, tokenFrontIs(), that
safely returns false when the deque is empty instead of dereferencing
front(), so malformed SQL_COMBINE values are now rejected with the
existing error-reporting/parse-failure path instead of crashing.
Co-Authored-By: Claude Opus 4.8 [email protected]