|
16 | 16 | import cpp
|
17 | 17 | import semmle.code.cpp.security.Security
|
18 | 18 | import semmle.code.cpp.security.FunctionWithWrappers
|
19 |
| -import semmle.code.cpp.ir.dataflow.internal.DefaultTaintTrackingImpl |
20 |
| -import TaintedWithPath |
| 19 | +import semmle.code.cpp.security.FlowSources |
| 20 | +import semmle.code.cpp.ir.dataflow.TaintTracking |
| 21 | +import semmle.code.cpp.ir.IR |
| 22 | +import Flow::PathGraph |
21 | 23 |
|
22 |
| -class Configuration extends TaintTrackingConfiguration { |
23 |
| - override predicate isSink(Element tainted) { |
24 |
| - exists(PrintfLikeFunction printf | printf.outermostWrapperFunctionCall(tainted, _)) |
| 24 | +predicate isSource(FlowSource source, string sourceType) { |
| 25 | + not source instanceof DataFlow::ExprNode and |
| 26 | + sourceType = source.getSourceType() |
| 27 | +} |
| 28 | + |
| 29 | +module Config implements DataFlow::ConfigSig { |
| 30 | + predicate isSource(DataFlow::Node node) { isSource(node, _) } |
| 31 | + |
| 32 | + predicate isSink(DataFlow::Node node) { |
| 33 | + exists(PrintfLikeFunction printf | |
| 34 | + printf.outermostWrapperFunctionCall([node.asExpr(), node.asIndirectExpr()], _) |
| 35 | + ) |
| 36 | + } |
| 37 | + |
| 38 | + private predicate isArithmeticNonCharType(ArithmeticType type) { |
| 39 | + not type instanceof CharType and |
| 40 | + not type instanceof Char8Type and |
| 41 | + not type instanceof Char16Type and |
| 42 | + not type instanceof Char32Type |
| 43 | + } |
| 44 | + |
| 45 | + predicate isBarrier(DataFlow::Node node) { |
| 46 | + isSink(node) and isArithmeticNonCharType(node.asExpr().getUnspecifiedType()) |
| 47 | + or |
| 48 | + isArithmeticNonCharType(node.asInstruction().(StoreInstruction).getResultType()) |
25 | 49 | }
|
26 | 50 | }
|
27 | 51 |
|
| 52 | +module Flow = TaintTracking::Global<Config>; |
| 53 | + |
28 | 54 | from
|
29 |
| - PrintfLikeFunction printf, Expr arg, PathNode sourceNode, PathNode sinkNode, |
30 |
| - string printfFunction, Expr userValue, string cause |
| 55 | + PrintfLikeFunction printf, string printfFunction, string sourceType, DataFlow::Node source, |
| 56 | + DataFlow::Node sink, Flow::PathNode sourceNode, Flow::PathNode sinkNode |
31 | 57 | where
|
32 |
| - printf.outermostWrapperFunctionCall(arg, printfFunction) and |
33 |
| - taintedWithPath(userValue, arg, sourceNode, sinkNode) and |
34 |
| - isUserInput(userValue, cause) |
35 |
| -select arg, sourceNode, sinkNode, |
| 58 | + source = sourceNode.getNode() and |
| 59 | + sink = sinkNode.getNode() and |
| 60 | + isSource(source, sourceType) and |
| 61 | + printf.outermostWrapperFunctionCall([sink.asExpr(), sink.asIndirectExpr()], printfFunction) and |
| 62 | + Flow::flowPath(sourceNode, sinkNode) |
| 63 | +select sink, sourceNode, sinkNode, |
36 | 64 | "The value of this argument may come from $@ and is being used as a formatting argument to " +
|
37 |
| - printfFunction + ".", userValue, cause |
| 65 | + printfFunction + ".", source, sourceType |
0 commit comments