Skip to content

Fix use-of-uninitialized-value in getURLHostRFC - #94851

Merged
alexey-milovidov merged 2 commits into
masterfrom
fix-domain-rfc-msan
Jan 22, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
fix-domain-rfc-msan

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jan 22, 2026 •

Copy link
Copy Markdown
Member

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.

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC) or LOGICAL_ERROR

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

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.

Version info

  • Merged into: 26.1.1.767
  • Backported to: 25.12.5.23, 25.11.8.20, 25.10.6.18, 25.8.16.15, 25.3.14.6

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]>
@clickhouse-gh

clickhouse-gh Bot commented Jan 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [331790d]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_tsan, 2/6) failure
test_backup_restore_s3/test.py::test_backup_to_s3_different_credentials[data_file_name_from_first_file_name-native_multipart] FAIL cidb, issue
BuzzHouse (amd_debug) failure
Logical error: 'Inconsistent AST formatting: the query: (STID: 1941-1bfa) FAIL cidb, issue

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Jan 22, 2026
@Algunenano Algunenano self-assigned this Jan 22, 2026
Comment thread src/Functions/URL/domain.h Outdated
/// @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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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]>
@alexey-milovidov
alexey-milovidov merged commit 69ea3e1 into master Jan 22, 2026
126 of 128 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-domain-rfc-msan branch January 22, 2026 22:02
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jan 22, 2026
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jan 22, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants