forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 19
Brodes/nested sizeof or operation in sizeof audit fixes #310
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
bdrodes
merged 2 commits into
main
from
brodes/nested_sizeof_or_operation_in_sizeof_audit_fixes
Dec 16, 2025
Merged
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
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
12 changes: 6 additions & 6 deletions
12
.../test/query-tests/Microsoft/Likely Bugs/SizeOfMisuse/ArgumentIsSizeofOrOperation.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,6 +1,6 @@ | ||
| | test.cpp:89:6:89:29 | sizeof(<expr>) | $@: $@ of $@ inside sizeof. | test.cpp:89:6:89:29 | sizeof(<expr>) | binary operator | test.cpp:66:6:66:11 | Test01 | Usage | test.cpp:89:13:89:28 | ... / ... | binary operator | | ||
| | test.cpp:96:6:96:30 | sizeof(<expr>) | $@: $@ of $@ inside sizeof. | test.cpp:96:6:96:30 | sizeof(<expr>) | binary operator | test.cpp:66:6:66:11 | Test01 | Usage | test.cpp:96:13:96:29 | ... * ... | binary operator | | ||
| | test.cpp:98:6:98:35 | sizeof(<expr>) | $@: $@ of $@ inside sizeof. | test.cpp:98:6:98:35 | sizeof(<expr>) | binary operator | test.cpp:66:6:66:11 | Test01 | Usage | test.cpp:98:13:98:34 | ... * ... | binary operator | | ||
| | test.cpp:101:6:101:31 | sizeof(<expr>) | $@: $@ of $@ inside sizeof. | test.cpp:101:6:101:31 | sizeof(<expr>) | sizeof | test.cpp:66:6:66:11 | Test01 | Usage | test.cpp:101:13:101:30 | sizeof(int) | sizeof | | ||
| | test.cpp:120:6:120:24 | sizeof(<expr>) | $@: $@ of $@ inside sizeof. | test.cpp:120:6:120:24 | sizeof(<expr>) | sizeof | test.cpp:66:6:66:11 | Test01 | Usage | test.cpp:120:13:120:23 | sizeof(int) | sizeof | | ||
| | test.cpp:121:6:121:18 | sizeof(<expr>) | $@: $@ of $@ inside sizeof. | test.cpp:121:6:121:18 | sizeof(<expr>) | binary operator | test.cpp:66:6:66:11 | Test01 | Usage | test.cpp:121:13:121:17 | ... + ... | binary operator | | ||
| | test.cpp:89:6:89:29 | sizeof(<expr>) | sizeof has a binary operator argument: $@. | test.cpp:89:13:89:28 | ... / ... | ... / ... | | ||
| | test.cpp:96:6:96:30 | sizeof(<expr>) | sizeof has a binary operator argument: $@. | test.cpp:96:13:96:29 | ... * ... | ... * ... | | ||
| | test.cpp:98:6:98:35 | sizeof(<expr>) | sizeof has a binary operator argument: $@. | test.cpp:98:13:98:34 | ... * ... | ... * ... | | ||
| | test.cpp:101:6:101:31 | sizeof(<expr>) | sizeof has a sizeof operation argument: $@. | test.cpp:101:13:101:30 | sizeof(int) | sizeof(int) | | ||
| | test.cpp:120:6:120:24 | sizeof(<expr>) | sizeof has a sizeof operation argument: $@. | test.cpp:120:13:120:23 | sizeof(int) | sizeof(int) | | ||
| | test.cpp:121:6:121:18 | sizeof(<expr>) | sizeof has a binary operator argument: $@. | test.cpp:121:13:121:17 | ... + ... | ... + ... | |
10 changes: 5 additions & 5 deletions
10
cpp/ql/test/query-tests/Microsoft/Likely Bugs/SizeOfMisuse/SizeOfConstIntMacro.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,5 @@ | ||
| | test.cpp:75:6:75:42 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test.cpp:75:6:75:42 | sizeof(<expr>) | Test01 | test.cpp:48:1:48:48 | #define SOMESTRUCT_ERRNO_THAT_MATTERS 0x8000000d | SOMESTRUCT_ERRNO_THAT_MATTERS | | ||
| | test.cpp:83:10:83:32 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test.cpp:83:10:83:32 | sizeof(<expr>) | Test01 | test.cpp:2:1:2:26 | #define BAD_MACRO_CONST 5l | BAD_MACRO_CONST | | ||
| | test.cpp:84:6:84:29 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test.cpp:84:6:84:29 | sizeof(<expr>) | Test01 | test.cpp:3:1:3:35 | #define BAD_MACRO_CONST2 0x80005001 | BAD_MACRO_CONST2 | | ||
| | test.cpp:92:7:92:35 | sizeof(<expr>) | $@: sizeof (in a macro expansion) of integer macro $@ will always return the size of the underlying integer type. | test.cpp:92:7:92:35 | sizeof(<expr>) | Test01 | test.cpp:1:1:1:19 | #define PAGESIZE 64 | PAGESIZE | | ||
| | test.cpp:116:6:116:37 | sizeof(<expr>) | $@: sizeof of integer macro $@ will always return the size of the underlying integer type. | test.cpp:116:6:116:37 | sizeof(<expr>) | Test01 | test.cpp:32:1:32:45 | #define ACE_CONDITION_SIGNATURE2 'xt' | ACE_CONDITION_SIGNATURE2 | | ||
| | test.cpp:75:6:75:42 | sizeof(<expr>) | sizeof of integer macro $@ will always return the size of the underlying integer type. | test.cpp:48:1:48:48 | #define SOMESTRUCT_ERRNO_THAT_MATTERS 0x8000000d | SOMESTRUCT_ERRNO_THAT_MATTERS | | ||
| | test.cpp:83:10:83:32 | sizeof(<expr>) | sizeof of integer macro $@ will always return the size of the underlying integer type. | test.cpp:2:1:2:26 | #define BAD_MACRO_CONST 5l | BAD_MACRO_CONST | | ||
| | test.cpp:84:6:84:29 | sizeof(<expr>) | sizeof of integer macro $@ will always return the size of the underlying integer type. | test.cpp:3:1:3:35 | #define BAD_MACRO_CONST2 0x80005001 | BAD_MACRO_CONST2 | | ||
| | test.cpp:92:7:92:35 | sizeof(<expr>) | sizeof (in a macro expansion) of integer macro $@ will always return the size of the underlying integer type. | test.cpp:1:1:1:19 | #define PAGESIZE 64 | PAGESIZE | | ||
| | test.cpp:116:6:116:37 | sizeof(<expr>) | sizeof of integer macro $@ will always return the size of the underlying integer type. | test.cpp:32:1:32:45 | #define ACE_CONDITION_SIGNATURE2 'xt' | ACE_CONDITION_SIGNATURE2 | |
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.
Did you really mean for
other.getUnspecifiedType() instanceof DerivedType? It's true that funmction pointers aren'tPointerTypes, but then I would have assumed that you would do:(or maybe
FunctionPointerIshType.), but you useDerivedTypewhich includes lots of other things such as reference types, andconst/volatiletypes (but you are callinggetUnspecifiedTypesoconst/volatiles are removed. All in all, this is very confusing 😂 Also, sincePointerTypes are alsoDerivedTypes what you wrote is equivalent to: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 missed they shared a common ancestor of derived. I should just make it instanceof Derived Type like you mentioned. I'll make that change. I don't mind that derived type includes other things, but I if Derived type does include specifiers for some reason... that is confusing. Basically I wanted to make the pattern as generic as possible. (TYPE*)0 == (other). I suppose I could maybe ignore "other's" type might be the most general solution.
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.
Diving more, yea it is confusing that derived type includes the const/volatile specifiers. That's unfortunate. I'm going to special case to just function pointer as you suggest and see if it changes my results. If not, I'll submit a new PR with this fix.