-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C++: CWE-190 Tests. #4266
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
Merged
Merged
C++: CWE-190 Tests. #4266
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions
2
cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/tainted/ArithmeticTainted.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
6 changes: 6 additions & 0 deletions
6
cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/tainted/IntegerOverflowTainted.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,9 +1,15 @@ | ||
| | test2.cpp:14:11:14:15 | ... * ... | $@ flows to here and is used in an expression which might overflow. | test2.cpp:25:22:25:23 | & ... | User-provided value | | ||
| | test2.cpp:16:11:16:21 | ... * ... | $@ flows to here and is used in an expression which might overflow. | test2.cpp:25:22:25:23 | & ... | User-provided value | | ||
| | test2.cpp:17:11:17:22 | ... * ... | $@ flows to here and is used in an expression which might overflow. | test2.cpp:25:22:25:23 | & ... | User-provided value | | ||
| | test3.c:12:31:12:34 | * ... | $@ flows to here and is used in an expression which might overflow negatively. | test3.c:11:15:11:18 | argv | User-provided value | | ||
| | test3.c:13:16:13:19 | * ... | $@ flows to here and is used in an expression which might overflow negatively. | test3.c:11:15:11:18 | argv | User-provided value | | ||
| | test4.cpp:13:17:13:20 | access to array | $@ flows to here and is used in an expression which might overflow negatively. | test4.cpp:9:13:9:16 | argv | User-provided value | | ||
| | test5.cpp:10:9:10:15 | call to strtoul | $@ flows to here and is used in an expression which might overflow. | test5.cpp:9:7:9:9 | buf | User-provided value | | ||
| | test5.cpp:17:6:17:27 | ... * ... | $@ flows to here and is used in an expression which might overflow. | test5.cpp:9:7:9:9 | buf | User-provided value | | ||
| | test5.cpp:19:6:19:13 | ... * ... | $@ flows to here and is used in an expression which might overflow. | test5.cpp:9:7:9:9 | buf | User-provided value | | ||
| | test6.cpp:11:15:11:15 | s | $@ flows to here and is used in an expression which might overflow. | test6.cpp:39:23:39:24 | & ... | User-provided value | | ||
| | test6.cpp:16:15:16:15 | s | $@ flows to here and is used in an expression which might overflow. | test6.cpp:39:23:39:24 | & ... | User-provided value | | ||
| | test6.cpp:30:16:30:16 | s | $@ flows to here and is used in an expression which might overflow. | test6.cpp:39:23:39:24 | & ... | User-provided value | | ||
| | test.c:14:15:14:35 | ... * ... | $@ flows to here and is used in an expression which might overflow. | test.c:11:29:11:32 | argv | User-provided value | | ||
| | test.c:44:7:44:12 | ... -- | $@ flows to here and is used in an expression which might overflow negatively. | test.c:41:17:41:20 | argv | User-provided value | | ||
| | test.c:54:7:54:12 | ... -- | $@ flows to here and is used in an expression which might overflow negatively. | test.c:51:17:51:20 | argv | User-provided value | |
28 changes: 28 additions & 0 deletions
28
cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/tainted/test2.cpp
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,28 @@ | ||
|
|
||
| typedef signed long long int s64; | ||
|
|
||
| typedef struct {} FILE; | ||
| int fscanf(FILE *stream, const char *format, ...); | ||
| FILE *stdin; | ||
|
|
||
| typedef struct _myStruct { | ||
| s64 val; | ||
| } MyStruct; | ||
|
|
||
| void test2_sink(s64 v, MyStruct s, MyStruct &s_r, MyStruct *s_p) | ||
| { | ||
| s64 v1 = v * 2; // bad | ||
| s64 v2 = s.val * 2; // bad [NOT DETECTED] | ||
| s64 v3 = s_r.val * 2; // bad | ||
| s64 v4 = s_p->val * 2; // bad | ||
| } | ||
|
|
||
| void test2_source() | ||
| { | ||
| MyStruct ms; | ||
| s64 v; | ||
|
|
||
| fscanf(stdin, "%i", &v); | ||
| ms.val = v; | ||
| test2_sink(v, ms, ms, &ms); | ||
| } | ||
54 changes: 54 additions & 0 deletions
54
cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/tainted/test6.cpp
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,54 @@ | ||
|
|
||
| typedef unsigned short u16; | ||
| typedef unsigned int u32; | ||
|
|
||
| typedef struct {} FILE; | ||
| int fscanf(FILE *stream, const char *format, ...); | ||
| FILE *stdin; | ||
|
|
||
| void docast1(u32 s) | ||
| { | ||
| u16 c = (u16)s; // bad | ||
| } | ||
|
|
||
| void docast2(u32 s) | ||
| { | ||
| u16 c = (u16)s; // bad | ||
| } | ||
|
|
||
| class MyBaseClass | ||
| { | ||
| public: | ||
| virtual void docast(u32 s) = 0; | ||
| }; | ||
|
|
||
| class MyDerivedClass : public MyBaseClass | ||
| { | ||
| public: | ||
| void docast(u32 s) | ||
| { | ||
| u16 c = (u16)s; // bad | ||
| } | ||
| }; | ||
|
|
||
| void test6() | ||
| { | ||
| u32 s; | ||
|
|
||
| s = -1; | ||
| fscanf(stdin, "%hd", &s); | ||
|
|
||
| docast1(s); | ||
| { | ||
| void (*docast2_ptr)(u32) = &docast2; | ||
|
|
||
| docast2_ptr(s); | ||
| } | ||
| { | ||
| MyBaseClass *mbc = new MyDerivedClass; | ||
|
|
||
| mbc->docast(s); | ||
|
|
||
| delete mbc; | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to simplify this. The type doesn't matter, I get the same results with
int.