Skip to content

Commit 076bcc0

Browse files
committed
C++: Remove use of 'FunctionWithWrappers' from 'cpp/tainted-format-string'.
1 parent 9b2b597 commit 076bcc0

1 file changed

Lines changed: 12 additions & 26 deletions

File tree

cpp/ql/src/Security/CWE/CWE-134/UncontrolledFormatString.ql

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,26 @@
1515

1616
import cpp
1717
import semmle.code.cpp.security.Security
18-
import semmle.code.cpp.security.FunctionWithWrappers
18+
import semmle.code.cpp.security.PrintfLike
1919
import semmle.code.cpp.security.FlowSources
2020
import semmle.code.cpp.ir.dataflow.TaintTracking
2121
import semmle.code.cpp.ir.IR
2222
import Flow::PathGraph
2323

2424
predicate isSource(FlowSource source, string sourceType) { sourceType = source.getSourceType() }
2525

26-
/**
27-
* Holds if `f` is a printf-like function or a (possibly nested) wrapper
28-
* that forwards a format-string parameter to one.
29-
*
30-
* Functions that *implement* printf-like behavior (e.g. a custom
31-
* `vsnprintf` variant) internally parse the caller-supplied format string
32-
* and build small, bounded, local format strings such as `"%d"` or `"%ld"`
33-
* for inner `sprintf` calls. Taint that reaches those inner calls via the
34-
* parsed format specifier is not exploitable, so sinks inside such
35-
* functions should be excluded.
36-
*/
37-
private predicate isPrintfImplementation(Function f) {
38-
f instanceof PrintfLikeFunction
39-
or
40-
exists(PrintfLikeFunction printf | printf.wrapperFunction(f, _, _))
26+
predicate isSink(DataFlow::Node node, Function f) {
27+
exists(Call c, int i |
28+
c.getTarget() = f and
29+
printfLikeFunction(f, i) and
30+
c.getArgument(i) = node.asIndirectExpr()
31+
)
4132
}
4233

4334
module Config implements DataFlow::ConfigSig {
4435
predicate isSource(DataFlow::Node node) { isSource(node, _) }
4536

46-
predicate isSink(DataFlow::Node node) {
47-
exists(PrintfLikeFunction printf |
48-
printf.outermostWrapperFunctionCall([node.asExpr(), node.asIndirectExpr()], _)
49-
) and
50-
not isPrintfImplementation([node.asExpr(), node.asIndirectExpr()].getEnclosingFunction())
51-
}
37+
predicate isSink(DataFlow::Node node) { isSink(node, _) }
5238

5339
private predicate isArithmeticNonCharType(ArithmeticType type) {
5440
not type instanceof CharType and
@@ -69,14 +55,14 @@ module Config implements DataFlow::ConfigSig {
6955
module Flow = TaintTracking::Global<Config>;
7056

7157
from
72-
PrintfLikeFunction printf, string printfFunction, string sourceType, DataFlow::Node source,
73-
DataFlow::Node sink, Flow::PathNode sourceNode, Flow::PathNode sinkNode
58+
Function printf, string sourceType, DataFlow::Node source, DataFlow::Node sink,
59+
Flow::PathNode sourceNode, Flow::PathNode sinkNode
7460
where
7561
source = sourceNode.getNode() and
7662
sink = sinkNode.getNode() and
7763
isSource(source, sourceType) and
78-
printf.outermostWrapperFunctionCall([sink.asExpr(), sink.asIndirectExpr()], printfFunction) and
64+
isSink(sink, printf) and
7965
Flow::flowPath(sourceNode, sinkNode)
8066
select sink, sourceNode, sinkNode,
8167
"The value of this argument may come from $@ and is being used as a formatting argument to " +
82-
printfFunction + ".", source, sourceType
68+
printf + ".", source, sourceType

0 commit comments

Comments
 (0)