Harden CLI parsing and enable unsafe-buffer diagnostics#176
Closed
netliomax25-code wants to merge 1 commit into
Closed
Harden CLI parsing and enable unsafe-buffer diagnostics#176netliomax25-code wants to merge 1 commit into
netliomax25-code wants to merge 1 commit into
Conversation
Owner
|
See #173 and CONTRIBUTING.md:
If you want to be able to enable |
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.
This PR improves the security hardening posture of the project by removing raw
argvrange pointer arithmetic from CLI parsing paths and enabling Clang's-Wunsafe-buffer-usagediagnostics where supported.The patch replaces direct pointer-range construction patterns such as:
args.assign(argv + 1, argv + argc);with explicit bounds-checked iteration using standard containers.
In addition, this PR introduces regression coverage for
ArgumentParser::ParseCLI(int, const char* const*)and enables compiler-assisted detection of unsafe buffer usage patterns.Security Rationale
This change improves the auditability and safety of CLI argument parsing by:
-Wunsafe-buffer-usagediagnostics to help prevent future regressionsargventries more defensivelyThe hardening approach aligns with modern secure-by-design buffer handling practices and supports ongoing migration away from unsafe buffer manipulation idioms.
Changes
args.hxxargv + 1, argv + argcvector assignment with explicit iterationexamples/gitlike.cxxargvpointer-range construction with explicit indexed iterationCMakeLists.txt-Wunsafe-buffer-usagewhen supported by ClangTests
Added a regression test covering:
ArgumentParser::ParseCLI(int, const char* const*)