C++: Fix FP on cpp/cleartext-transmission#21857
Open
MathiasVP wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a false positive in the C++ cpp/cleartext-transmission query by refining the fscanf remote-source model so the analysis can distinguish socket-backed streams from obviously local streams (for example, stdin). It also adds a regression test and corresponding change notes for both the query and library packs.
Changes:
- Refine the
fscanfmodel by implementingRemoteFlowSourceFunction.hasSocketInput. - Add a regression test case ensuring
fscanf(stdin, ...)is not treated as a remote source. - Add change notes documenting the query-result change and the underlying library model change.
Show a summary per file
| File | Description |
|---|---|
| cpp/ql/lib/semmle/code/cpp/models/implementations/Scanf.qll | Updates the fscanf model to implement hasSocketInput. |
| cpp/ql/test/query-tests/Security/CWE/CWE-311/semmle/tests/test3.cpp | Adds a regression test for fscanf(stdin, ...) being treated as local. |
| cpp/ql/src/change-notes/2026-05-15-cleartext-transmission-fp.md | Documents the cpp/cleartext-transmission false-positive reduction. |
| cpp/ql/lib/change-notes/2026-05-15-hasSocketInput-for-fscanf.md | Documents the library model refinement for fscanf. |
Copilot's findings
- Files reviewed: 4/4 changed files
- Comments generated: 2
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 query did not recognize that
fscanfis potentially not a remote flow source because we didn't override the optionalhasSocketInputpredicate onRemoteFlowSourceFunction.DCA shows lots of removed results in SAMATE. They're all instances of exactly the pattern I added in the query test: a
fscanfcall that writes tostdin.