-
Notifications
You must be signed in to change notification settings - Fork 2k
C++: Model secure versions of scanf as flow sources
#21856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MathiasVP
wants to merge
5
commits into
github:main
Choose a base branch
from
MathiasVP:scanf-safe-functions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2902a19
C++: Add more scanf testing.
MathiasVP 16235d7
C++: Add a 'call' column to 'hasRemoteFlowSource' and 'hasLocalFlowSo…
MathiasVP 5add24b
C++: Add scanf_s models.
MathiasVP 5f10a88
C++: Handle size arguments in 'getOutputArgument'.
MathiasVP 19781e5
C++: Add change notes.
MathiasVP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| category: minorAnalysis | ||
| --- | ||
| * Added flow source models for `scanf_s` and related functions. | ||
| * Added a `Call` column to `LocalFlowSourceFunction::hasLocalFlowSource` and `RemoteFlowSourceFunction::hasRemoteFlowSource`. The old predicates without a `Call` column continue to be supported. |
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
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
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
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
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
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
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
13 changes: 8 additions & 5 deletions
13
cpp/ql/test/library-tests/scanf/scanfFormatLiteral.expected
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| | test.c:18:2:18:6 | call to scanf | 0 | s | 0 | 0 | | ||
| | test.c:19:2:19:7 | call to fscanf | 0 | s | 10 | 10 | | ||
| | test.c:19:2:19:7 | call to fscanf | 1 | i | 0 | 0 | | ||
| | test.c:20:2:20:7 | call to sscanf | 0 | s | 0 | 0 | | ||
| | test.c:21:2:21:8 | call to swscanf | 0 | s | 10 | 10 | | ||
| | test.c:19:2:19:6 | call to scanf | 0 | s | 0 | 0 | | ||
| | test.c:20:2:20:7 | call to fscanf | 0 | s | 10 | 10 | | ||
| | test.c:20:2:20:7 | call to fscanf | 1 | i | 0 | 0 | | ||
| | test.c:21:2:21:7 | call to sscanf | 0 | s | 0 | 0 | | ||
| | test.c:22:2:22:8 | call to swscanf | 0 | s | 10 | 10 | | ||
| | test.c:23:2:23:8 | call to scanf_s | 0 | d | 0 | 0 | | ||
| | test.c:23:2:23:8 | call to scanf_s | 1 | s | 0 | 0 | | ||
| | test.c:23:2:23:8 | call to scanf_s | 2 | d | 0 | 0 | |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| | ms.cpp:17:3:17:8 | call to sscanf | 0 | 1 | ms.cpp:17:24:17:30 | %I64i | non-wide | | ||
| | test.c:18:2:18:6 | call to scanf | 0 | 0 | test.c:18:8:18:11 | %s | non-wide | | ||
| | test.c:19:2:19:7 | call to fscanf | 0 | 1 | test.c:19:15:19:23 | %10s %i | non-wide | | ||
| | test.c:20:2:20:7 | call to sscanf | 0 | 1 | test.c:20:19:20:28 | %*i%s%*s | non-wide | | ||
| | test.c:21:2:21:8 | call to swscanf | 0 | 1 | test.c:21:21:21:26 | %10s | wide | | ||
| | test.c:19:2:19:6 | call to scanf | 0 | 0 | test.c:19:8:19:11 | %s | non-wide | | ||
| | test.c:20:2:20:7 | call to fscanf | 0 | 1 | test.c:20:15:20:23 | %10s %i | non-wide | | ||
| | test.c:21:2:21:7 | call to sscanf | 0 | 1 | test.c:21:19:21:28 | %*i%s%*s | non-wide | | ||
| | test.c:22:2:22:8 | call to swscanf | 0 | 1 | test.c:22:21:22:26 | %10s | wide | | ||
| | test.c:23:2:23:8 | call to scanf_s | 0 | 0 | test.c:23:10:23:19 | %d %s %d | non-wide | |
9 changes: 9 additions & 0 deletions
9
cpp/ql/test/library-tests/scanf/scanfFunctionCallOutput.expected
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| | ms.cpp:17:3:17:8 | call to sscanf | ms.cpp:17:33:17:36 | & ... | 0 | | ||
| | test.c:19:2:19:6 | call to scanf | test.c:19:14:19:19 | buffer | 0 | | ||
| | test.c:20:2:20:7 | call to fscanf | test.c:20:26:20:31 | buffer | 0 | | ||
| | test.c:20:2:20:7 | call to fscanf | test.c:20:34:20:34 | i | 1 | | ||
| | test.c:21:2:21:7 | call to sscanf | test.c:21:31:21:36 | buffer | 0 | | ||
| | test.c:22:2:22:8 | call to swscanf | test.c:22:29:22:35 | wbuffer | 0 | | ||
| | test.c:23:2:23:8 | call to scanf_s | test.c:23:22:23:23 | & ... | 0 | | ||
| | test.c:23:2:23:8 | call to scanf_s | test.c:23:26:23:31 | buffer | 1 | | ||
| | test.c:23:2:23:8 | call to scanf_s | test.c:23:38:23:40 | & ... | 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import semmle.code.cpp.commons.Scanf | ||
|
|
||
| from ScanfFunctionCall sfc, Expr e, int n | ||
| where e = sfc.getOutputArgument(n) | ||
| select sfc, e, n |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.