-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C++: exclude printf implementation internals from uncontrolled format string sinks #21493
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,13 +23,32 @@ | |||||||
|
|
||||||||
| predicate isSource(FlowSource source, string sourceType) { sourceType = source.getSourceType() } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Holds if `f` is a printf-like function or a (possibly nested) wrapper | ||||||||
| * that forwards a format-string parameter to one. | ||||||||
| * | ||||||||
| * Functions that *implement* printf-like behaviour (e.g. a custom | ||||||||
| * `vsnprintf` variant) internally parse the caller-supplied format string | ||||||||
| * and build small, bounded, local format strings such as `"%d"` or `"%ld"` | ||||||||
| * for inner `sprintf` calls. Taint that reaches those inner calls via the | ||||||||
| * parsed format specifier is not exploitable, so sinks inside such | ||||||||
| * functions should be excluded. | ||||||||
| */ | ||||||||
Check warningCode scanning / CodeQL Misspelling Warning
This comment contains the non-US spelling 'behaviour', which should instead be 'behavior'.
|
||||||||
|
Comment on lines
+26
to
+36
|
||||||||
| private predicate isPrintfImplementation(Function f) { | ||||||||
| f instanceof PrintfLikeFunction | ||||||||
| or | ||||||||
| exists(PrintfLikeFunction printf | printf.wrapperFunction(f, _, _)) | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit worried this last line may be too inclusive. A bit of testing should confirm one way or another... |
||||||||
| } | ||||||||
|
|
||||||||
| module Config implements DataFlow::ConfigSig { | ||||||||
| predicate isSource(DataFlow::Node node) { isSource(node, _) } | ||||||||
|
|
||||||||
| predicate isSink(DataFlow::Node node) { | ||||||||
| exists(PrintfLikeFunction printf | | ||||||||
| printf.outermostWrapperFunctionCall([node.asExpr(), node.asIndirectExpr()], _) | ||||||||
| ) | ||||||||
| ) and | ||||||||
| not isPrintfImplementation(node.asExpr().getEnclosingFunction()) and | ||||||||
| not isPrintfImplementation(node.asIndirectExpr().getEnclosingFunction()) | ||||||||
|
Comment on lines
+50
to
+51
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use the
Suggested change
|
||||||||
| } | ||||||||
|
|
||||||||
| private predicate isArithmeticNonCharType(ArithmeticType type) { | ||||||||
|
|
||||||||
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.
Copilot is right, we prefer American spellings in documentation, including in
/**comments that may be extracted to documentation.