Skip to content

[6.40] Fix potential buffer overflow in TString#22280

Merged
bellenot merged 1 commit into
root-project:v6-40-00-patchesfrom
root-project-bot:BP_6.40_pull_22228
May 13, 2026
Merged

[6.40] Fix potential buffer overflow in TString#22280
bellenot merged 1 commit into
root-project:v6-40-00-patchesfrom
root-project-bot:BP_6.40_pull_22228

Conversation

@root-project-bot
Copy link
Copy Markdown

Backport of #22228, requested by @bellenot.

…#22228)

As reported here: https://github.com/root-project/root/security/code-scanning/1843
- Fixes root-project#22218
- Fixes https://github.com/root-project/root/security/code-scanning/1843
TString::FormImp used a heuristic buffer size and passed an assumed
length to vsnprintf, which static analyzers could not prove matched
the actual allocated buffer. In addition, the same va_list was reused
across multiple vsnprintf calls, resulting in undefined behavior on
some platforms.
The implementation was rewritten to use a two‑pass vsnprintf approach:
the first pass computes the exact required length, and Clobber() is
used to allocate sufficient space including the null terminator.
A second pass formats the string into the allocated buffer using a
fresh va_list copy.
This change:
- Guarantees that the size passed to vsnprintf matches the allocated buffer
- Eliminates undefined behavior from va_list reuse
- Removes heuristic resizing loops
- Silences static analysis warnings for legitimate reasons
- Preserves existing TString semantics and limits

(cherry picked from commit e217071)
@github-actions
Copy link
Copy Markdown

Test Results

    22 files      22 suites   3d 10h 32m 16s ⏱️
 3 850 tests  3 849 ✅ 0 💤 1 ❌
76 042 runs  76 041 ✅ 0 💤 1 ❌

For more details on these failures, see this check.

Results for commit 413931c.

@bellenot bellenot merged commit bc65ef9 into root-project:v6-40-00-patches May 13, 2026
31 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants