Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion cpp/ql/src/Security/CWE/CWE-134/UncontrolledFormatString.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
MarkLee131 marked this conversation as resolved.
Outdated
* `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 warning

Code scanning / CodeQL

Misspelling Warning

This comment contains the non-US spelling 'behaviour', which should instead be 'behavior'.
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
private predicate isPrintfImplementation(Function f) {
f instanceof PrintfLikeFunction
or
exists(PrintfLikeFunction printf | printf.wrapperFunction(f, _, _))
Comment thread
geoffw0 marked this conversation as resolved.
}

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 thread
MarkLee131 marked this conversation as resolved.
Outdated
}

private predicate isArithmeticNonCharType(ArithmeticType type) {
Expand Down
Loading