|
14 | 14 |
|
15 | 15 | import cpp |
16 | 16 | import semmle.code.cpp.security.Security |
17 | | -import semmle.code.cpp.ir.dataflow.internal.DefaultTaintTrackingImpl |
18 | | -import TaintedWithPath |
| 17 | +import semmle.code.cpp.security.FlowSources |
| 18 | +import semmle.code.cpp.ir.dataflow.TaintTracking |
| 19 | +import semmle.code.cpp.ir.IR |
| 20 | +import Flow::PathGraph |
19 | 21 |
|
20 | | -predicate isProcessOperationExplanation(Expr arg, string processOperation) { |
| 22 | +predicate isProcessOperationExplanation(DataFlow::Node arg, string processOperation) { |
21 | 23 | exists(int processOperationArg, FunctionCall call | |
22 | 24 | isProcessOperationArgument(processOperation, processOperationArg) and |
23 | 25 | call.getTarget().getName() = processOperation and |
24 | | - call.getArgument(processOperationArg) = arg |
| 26 | + call.getArgument(processOperationArg) = [arg.asExpr(), arg.asIndirectExpr()] |
25 | 27 | ) |
26 | 28 | } |
27 | 29 |
|
28 | | -class Configuration extends TaintTrackingConfiguration { |
29 | | - override predicate isSink(Element arg) { isProcessOperationExplanation(arg, _) } |
| 30 | +predicate isSource(FlowSource source, string sourceType) { |
| 31 | + not source instanceof DataFlow::ExprNode and |
| 32 | + sourceType = source.getSourceType() |
30 | 33 | } |
31 | 34 |
|
32 | | -from string processOperation, Expr arg, Expr source, PathNode sourceNode, PathNode sinkNode |
| 35 | +module Config implements DataFlow::ConfigSig { |
| 36 | + predicate isSource(DataFlow::Node node) { isSource(node, _) } |
| 37 | + |
| 38 | + predicate isSink(DataFlow::Node node) { isProcessOperationExplanation(node, _) } |
| 39 | + |
| 40 | + predicate isBarrier(DataFlow::Node node) { |
| 41 | + isSink(node) and node.asExpr().getUnspecifiedType() instanceof ArithmeticType |
| 42 | + or |
| 43 | + node.asInstruction().(StoreInstruction).getResultType() instanceof ArithmeticType |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +module Flow = TaintTracking::Global<Config>; |
| 48 | + |
| 49 | +from |
| 50 | + string processOperation, string sourceType, DataFlow::Node source, DataFlow::Node sink, |
| 51 | + Flow::PathNode sourceNode, Flow::PathNode sinkNode |
33 | 52 | where |
34 | | - isProcessOperationExplanation(arg, processOperation) and |
35 | | - taintedWithPath(source, arg, sourceNode, sinkNode) |
36 | | -select arg, sourceNode, sinkNode, |
| 53 | + source = sourceNode.getNode() and |
| 54 | + sink = sinkNode.getNode() and |
| 55 | + isSource(source, sourceType) and |
| 56 | + isProcessOperationExplanation(sink, processOperation) and |
| 57 | + Flow::flowPath(sourceNode, sinkNode) |
| 58 | +select sink, sourceNode, sinkNode, |
37 | 59 | "The value of this argument may come from $@ and is being passed to " + processOperation + ".", |
38 | | - source, source.toString() |
| 60 | + source, sourceType |
0 commit comments