-
Notifications
You must be signed in to change notification settings - Fork 1.9k
CPP: Better handling of %s/%c/%S/%C in Printf/FormattingFunction.qll #1119
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
162c998
CPP: Add some test cases.
geoffw0 648cdba
CPP: Add FormattingFunction.getFormatCharType() and test.
geoffw0 975a0bb
CPP: Handle %s/%c/%S/%C correctly on non-MS platforms.
geoffw0 4a25c37
CPP: Detect Microsoft compilations somewhat more reliably.
geoffw0 eef050d
CPP: Improve deduction of %S types in FormattingFunction.qll.
geoffw0 5911699
CPP: Clean up some remaining old 'isWideCharDefault' logic that has c…
geoffw0 66e87fc
CPP: Detect Microsoft compilations even more reliably.
geoffw0 d22c93f
CPP: Change note.
geoffw0 f5a7d7a
CPP: Correct a few comments.
geoffw0 c8caca3
CPP: Add test cases for %ls, %hs.
geoffw0 a6e0296
CPP: Be slash/case insensitive.
geoffw0 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
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
20 changes: 12 additions & 8 deletions
20
...ormat/WrongTypeFormatArguments/Linux_mixed_byte_wprintf/WrongTypeFormatArguments.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,10 +1,14 @@ | ||
| | tests.cpp:18:15:18:22 | Hello | This argument should be of type 'char *' but is of type 'char16_t *' | | ||
| | tests.cpp:19:15:19:22 | Hello | This argument should be of type 'char *' but is of type 'wchar_t *' | | ||
| | tests.cpp:25:17:25:23 | Hello | This argument should be of type 'wchar_t *' but is of type 'char *' | | ||
| | tests.cpp:26:17:26:24 | Hello | This argument should be of type 'wchar_t *' but is of type 'char16_t *' | | ||
| | tests.cpp:30:17:30:24 | Hello | This argument should be of type 'char *' but is of type 'char16_t *' | | ||
| | tests.cpp:31:17:31:24 | Hello | This argument should be of type 'char *' but is of type 'wchar_t *' | | ||
| | tests.cpp:33:36:33:42 | Hello | This argument should be of type 'char16_t *' but is of type 'char *' | | ||
| | tests.cpp:35:36:35:43 | Hello | This argument should be of type 'char16_t *' but is of type 'wchar_t *' | | ||
| | tests.cpp:38:36:38:43 | Hello | This argument should be of type 'char *' but is of type 'char16_t *' | | ||
| | tests.cpp:39:36:39:43 | Hello | This argument should be of type 'char *' but is of type 'wchar_t *' | | ||
| | tests.cpp:26:17:26:24 | Hello | This argument should be of type 'char *' but is of type 'char16_t *' | | ||
| | tests.cpp:27:17:27:24 | Hello | This argument should be of type 'char *' but is of type 'wchar_t *' | | ||
| | tests.cpp:29:17:29:23 | Hello | This argument should be of type 'wchar_t *' but is of type 'char *' | | ||
| | tests.cpp:30:17:30:24 | Hello | This argument should be of type 'wchar_t *' but is of type 'char16_t *' | | ||
| | tests.cpp:34:36:34:43 | Hello | This argument should be of type 'char *' but is of type 'char16_t *' | | ||
| | tests.cpp:35:36:35:43 | Hello | This argument should be of type 'char *' but is of type 'wchar_t *' | | ||
| | tests.cpp:37:36:37:42 | Hello | This argument should be of type 'char16_t *' but is of type 'char *' | | ||
| | tests.cpp:39:36:39:43 | Hello | This argument should be of type 'char16_t *' but is of type 'wchar_t *' | | ||
| | tests.cpp:42:37:42:44 | Hello | This argument should be of type 'char *' but is of type 'char16_t *' | | ||
| | tests.cpp:43:37:43:44 | Hello | This argument should be of type 'char *' but is of type 'wchar_t *' | | ||
| | tests.cpp:45:37:45:43 | Hello | This argument should be of type 'char16_t *' but is of type 'char *' | | ||
| | tests.cpp:47:37:47:44 | Hello | This argument should be of type 'char16_t *' but is of type 'wchar_t *' | |
6 changes: 3 additions & 3 deletions
6
...Bugs/Format/WrongTypeFormatArguments/Linux_mixed_byte_wprintf/formattingFunction.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,3 +1,3 @@ | ||
| | tests.cpp:8:5:8:10 | printf | char | char16_t, wchar_t | char16_t, wchar_t | | ||
| | tests.cpp:9:5:9:11 | wprintf | wchar_t | char | wchar_t | | ||
| | tests.cpp:10:5:10:12 | swprintf | char16_t | char | char16_t | | ||
| | tests.cpp:8:5:8:10 | printf | char | char | char16_t, wchar_t | char16_t, wchar_t | | ||
| | tests.cpp:9:5:9:11 | wprintf | wchar_t | char | wchar_t | wchar_t | | ||
| | tests.cpp:10:5:10:12 | swprintf | char16_t | char | char16_t | char16_t | |
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
1 change: 1 addition & 0 deletions
1
.../Format/WrongTypeFormatArguments/Linux_two_byte_wprintf/WrongTypeFormatArguments.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,2 +1,3 @@ | ||
| | printf.cpp:33:31:33:37 | test | This argument should be of type 'char *' but is of type 'char16_t *' | | ||
| | printf.cpp:45:29:45:35 | test | This argument should be of type 'char *' but is of type 'char16_t *' | | ||
| | printf.cpp:52:29:52:35 | test | This argument should be of type 'char16_t *' but is of type 'wchar_t *' | |
2 changes: 1 addition & 1 deletion
2
...y Bugs/Format/WrongTypeFormatArguments/Linux_two_byte_wprintf/formattingFunction.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,2 +1,2 @@ | ||
| | printf.cpp:15:5:15:12 | swprintf | char16_t | char | char16_t | | ||
| | printf.cpp:15:5:15:12 | swprintf | char | char16_t | char16_t | | ||
| | printf.cpp:26:5:26:11 | sprintf | char | char16_t | char16_t | |
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
2 changes: 1 addition & 1 deletion
2
...ely Bugs/Format/WrongTypeFormatArguments/Linux_unsigned_chars/formattingFunction.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 @@ | ||
| | common.h:12:12:12:17 | printf | char | wchar_t | wchar_t | | ||
| | common.h:15:12:15:18 | wprintf | wchar_t | char | wchar_t | | ||
| | common.h:15:12:15:18 | wprintf | char | wchar_t | wchar_t | | ||
| | format.h:4:13:4:17 | error | char | wchar_t | wchar_t | | ||
| | real_world.h:8:12:8:18 | fprintf | char | wchar_t | wchar_t | | ||
| | real_world.h:33:6:33:12 | msg_out | char | wchar_t | wchar_t | |
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
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.
Matching on
\cl.exeseems fragile to me; for example, what if it's written in upper case or with a forward slash? @ian-semmle, is this the best we can do? Why don't we always get a--microsoftargument?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.
We discussed the matter on Slack a few days ago, and agreed that the right way would be for the extractor to tell us explicitly whether a compilation was Microsoft or not.
Right now we might get slightly better accuracy by looking for the existence of the
_MSC_VERmacro anywhere in the snapshot, though we'll just have to assume that all files are compiled as Microsoft if we see it (so we'll do worse in the probably very rare case of mixed Microsoft and non-Microsoft compilations). Another suggestion was looking for paths beginningC:or similar (which detects a Microsoft file system, rather than compiler, and may work poorly with test path normalization).I'm happy to implement the
_MSC_VERthing if you're convinced it would be preferable. Or just make thecl.execlause a bit more robust?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.
In that case, it sounds better to make the
cl.exetest more robust. Is it only relevant to test forcl.exewhen there's also a--mimicargument?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.
Yes I think so. My logic was that with matching the
\, it's highly unlikely we'll get false results forcl.exe.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.
A quick Google search shows that some people like to spell it
CL.exe, so turning the match into a case-insensitive regex might be necessary. WhatCompilationargument do we get if the compiler is just invoked ascl, without the.exe? Or the--mimicoption only work if.exeis included? I suppose this argument is only ever produced by our own tracer, so your current match might be fine if the tracer normalises everything.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've made it slash/case insensitive, that seems pretty uncontroversial. Removing the need for
.exeseems riskier to me asclby itself is a very short string that could coincidentally match something else (e.g. some command line flag that happens to be/CL).