Repository navigation
Fix UBSan error in Lexer::nextToken: null pointer arithmetic - #102302
alexey-milovidov wants to merge 11 commits into
Conversation
When `Lexer` is constructed with a null buffer (begin = nullptr) and non-zero `max_query_size`, the expression `begin + max_query_size` is undefined behavior. This was triggered by the `FunctionsStress.stress` test in CI. Add a null check for `begin` before the pointer arithmetic. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [f335e91] Summary: ❌
AI ReviewSummaryThis PR fixes undefined behavior in ClickHouse Rules
Final Verdict
|
…= 1`
The test case `SELECT formatQueryOrNull('SELECT 1') SETTINGS max_query_size = 1`
fails because `max_query_size = 1` applies to the outer query's parsing on the
server, not just to `formatQueryOrNull`'s internal parsing. The outer query
exceeds 1 byte and gets a syntax error before the function is even called.
The empty string test case is sufficient to exercise the null-buffer Lexer path,
and the unit test in `gtest_Lexer.cpp` covers the direct path.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…n-ubsan # Conflicts: # src/Parsers/Lexer.cpp
| @@ -0,0 +1,6 @@ | |||
| -- Regression test: Lexer with null begin pointer and non-zero max_query_size | |||
There was a problem hiding this comment.
This test case does not actually cover the nullptr-begin path from the UB report. In formatQueryOrNull, begin is taken from ColumnString storage (&data[prev_offset]), so for '' it is an empty buffer pointer (begin == end) but still non-null. That means this SQL test would pass even without the null-pointer arithmetic fix in Lexer.
Please either adjust the test description to avoid claiming null begin pointer coverage, or add a path that truly constructs Lexer(nullptr, nullptr, max_query_size) (the new gtest_Lexer already does this).
The SQL test exercises `formatQueryOrNull('')`, where `begin` is a
non-null empty-buffer pointer from `ColumnString` storage, not
`nullptr`. The actual null-pointer arithmetic path that triggered
UBSan in `Lexer::nextToken` is covered directly by
`gtest_Lexer.cpp` (`Lexer.NullBuffer`).
Update the comment so it does not claim coverage of the null
begin pointer case.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: 100.00% (2/2) · Uncovered code |
|
Some how the code with the fix is vanished from this PR. |
When
Lexeris constructed with a null buffer (begin= nullptr) and non-zeromax_query_size, the expressionbegin + max_query_sizeinLexer::nextTokenis undefined behavior (adding a non-zero offset to a null pointer). This was triggered by theFunctionsStress.stresstest in CI.The fix adds a null check for
beginbefore the pointer arithmetic.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix undefined behavior in
Lexerwhen constructed with a null buffer and non-zeromax_query_size.Documentation entry for user-facing changes