Repository navigation
Fix use-of-uninitialized-value in getURLHostRFC - #94851
Merged
Merged
Conversation
The `getURLHostRFC` function was missing bounds checks before dereferencing pointers. When an empty string was passed to `domainRFC`, it would read uninitialized memory, triggering MSan errors. Added early return for empty input and size check before dereferencing `*(pos + 1)`, matching the pattern already used in `getURLHost`. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Contributor
|
Workflow [PR], commit [331790d] Summary: ❌
|
Algunenano
reviewed
Jan 22, 2026
| /// @return empty string view if the host is not valid (i.e. it does not have dot, or there no symbol after dot). | ||
| inline std::string_view getURLHostRFC(const char * data, size_t size) | ||
| { | ||
| if (size == 0) |
Member
There was a problem hiding this comment.
Can we do this instead of the 2 checks?:
if (size < 2)
return std::string_view{};
Co-Authored-By: Claude Opus 4.5 <[email protected]>
Algunenano
approved these changes
Jan 22, 2026
This was referenced Jan 22, 2026
robot-clickhouse
added a commit
that referenced
this pull request
Jan 26, 2026
robot-clickhouse
added a commit
that referenced
this pull request
Jan 26, 2026
robot-clickhouse
added a commit
that referenced
this pull request
Jan 26, 2026
robot-clickhouse
added a commit
that referenced
this pull request
Jan 26, 2026
robot-clickhouse
added a commit
that referenced
this pull request
Jan 26, 2026
clickhouse-gh Bot
added a commit
that referenced
this pull request
Jan 26, 2026
Backport #94851 to 25.10: Fix use-of-uninitialized-value in `getURLHostRFC`
clickhouse-gh Bot
added a commit
that referenced
this pull request
Jan 26, 2026
Backport #94851 to 25.8: Fix use-of-uninitialized-value in `getURLHostRFC`
Algunenano
added a commit
that referenced
this pull request
Jan 26, 2026
Backport #94851 to 25.12: Fix use-of-uninitialized-value in `getURLHostRFC`
Algunenano
added a commit
that referenced
this pull request
Jan 26, 2026
Backport #94851 to 25.11: Fix use-of-uninitialized-value in `getURLHostRFC`
Algunenano
added a commit
that referenced
this pull request
Jan 26, 2026
Backport #94851 to 25.3: Fix use-of-uninitialized-value in `getURLHostRFC`
otselnik
pushed a commit
to otselnik/ClickHouse
that referenced
this pull request
Sep 10, 2026
`getURLHostRFC` consumes the scheme prefix and then dereferences `*pos` at
domain.h:82 (`if (*pos == '[')`) before entering its bounded scan loop at
:93. For an authority that ends exactly at the prefix, `pos == end`, so that
read is one byte past the input.
That byte is uninitialised heap rather than a harmless terminator:
`ColumnString` is not zero-terminated (ColumnString.h:40),
`ColumnString::insert` appends exactly `s.size` bytes with a plain memcpy,
StringHelpers.h:82 passes exactly `offsets[i] - prev_offset` with no -1, and
`PODArrayBase::alloc` initialises only one `pad_left` element. `pos == end`
is reachable from "//" (`pos += 2`) and from "<scheme>://" (`pos += 3`), so
`SELECT domainRFC('http://')` is enough to trigger it. On an MSan build the
server aborts; the AST fuzzer hit it in Stress test (amd_msan) after
mutating `firstSignificantSubdomain` to `domainRFC` in
00381_first_significant_subdomain.sql. MSan names :93 rather than :82
because clang if-converts the bracket test, so the first branch on the
tainted byte is the loop guard.
The read has been unguarded since a2d451d (ClickHouse#53506) added IPv6 bracket
support in 2023, and is still unguarded on 25.3, 25.8 and 26.8. The
non-RFC `getURLHost` is safe because it has no dereference between the
prefix advance and its loop, which is the shape restored here; the same
one-line shape was used by the two earlier fixes to this class in this
function, ClickHouse#86171 and ClickHouse#94851. All ten user-facing RFC functions reach the
defect through this single call site, so all ten are fixed at once.
The guard is behaviour-preserving: every `pos == end` path already returned
an empty host. Measured over 30422 generated inputs against 13 URL
functions on a fixed and a reverted build, the output is byte-identical, so
no existing reference file changes.
There is no functional oracle for the defect, and none is invented here:
the MSan build is the oracle, as it was for the test added by ClickHouse#94851.
03801_domain_empty_string_msan gains nine truncated-authority queries: the
literal that fired in CI, two further `domainRFC` literals, five more
user-facing RFC entry points, and the same input behind `materialize` for
the vectorized route. The test uses more than one truncated-authority
literal because MSan does not emit the report at every input length on the
builds measured here.
Co-Authored-By: Claude Opus 5 <[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
getURLHostRFCfunction was missing bounds checks before dereferencing pointers. When an empty string was passed todomainRFC, it would read uninitialized memory, triggering MSan errors.Added early return for empty input and size check before dereferencing
*(pos + 1), matching the pattern already used ingetURLHost.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The
getURLHostRFCfunction was missing bounds checks before dereferencing pointers. When an empty string was passed todomainRFC, it would read uninitialized memory, triggering MSan errors.Version info
26.1.1.76725.12.5.23,25.11.8.20,25.10.6.18,25.8.16.15,25.3.14.6