|
17 | 17 | import cpp |
18 | 18 | import semmle.code.cpp.security.FunctionWithWrappers |
19 | 19 | import semmle.code.cpp.security.Security |
20 | | -import semmle.code.cpp.security.TaintTracking |
21 | | -import TaintedWithPath |
| 20 | +import semmle.code.cpp.ir.IR |
| 21 | +import semmle.code.cpp.ir.dataflow.TaintTracking |
| 22 | +import DataFlow::PathGraph |
22 | 23 |
|
23 | 24 | /** |
24 | 25 | * A function for opening a file. |
@@ -46,18 +47,42 @@ class FileFunction extends FunctionWithWrappers { |
46 | 47 | override predicate interestingArg(int arg) { arg = 0 } |
47 | 48 | } |
48 | 49 |
|
49 | | -class TaintedPathConfiguration extends TaintTrackingConfiguration { |
50 | | - override predicate isSink(Element tainted) { |
51 | | - exists(FileFunction fileFunction | fileFunction.outermostWrapperFunctionCall(tainted, _)) |
| 50 | +Expr asSourceExpr(DataFlow::Node node) { |
| 51 | + result in [node.asConvertedExpr(), node.asDefiningArgument()] |
| 52 | +} |
| 53 | + |
| 54 | +Expr asSinkExpr(DataFlow::Node node) { |
| 55 | + result = node.asConvertedExpr() |
| 56 | + or |
| 57 | + result = |
| 58 | + node.asOperand() |
| 59 | + .(SideEffectOperand) |
| 60 | + .getUse() |
| 61 | + .(ReadSideEffectInstruction) |
| 62 | + .getArgumentDef() |
| 63 | + .getUnconvertedResultExpression() |
| 64 | +} |
| 65 | + |
| 66 | +class TaintedPathConfiguration extends TaintTracking::Configuration { |
| 67 | + TaintedPathConfiguration() { this = "TaintedPathConfiguration" } |
| 68 | + |
| 69 | + override predicate isSource(DataFlow::Node node) { isUserInput(asSourceExpr(node), _) } |
| 70 | + |
| 71 | + override predicate isSink(DataFlow::Node node) { |
| 72 | + exists(FileFunction fileFunction | |
| 73 | + fileFunction.outermostWrapperFunctionCall(asSinkExpr(node), _) |
| 74 | + ) |
52 | 75 | } |
53 | 76 | } |
54 | 77 |
|
55 | 78 | from |
56 | | - FileFunction fileFunction, Expr taintedArg, Expr taintSource, PathNode sourceNode, |
57 | | - PathNode sinkNode, string taintCause, string callChain |
| 79 | + FileFunction fileFunction, Expr taintedArg, Expr taintSource, TaintedPathConfiguration cfg, |
| 80 | + DataFlow::PathNode sourceNode, DataFlow::PathNode sinkNode, string taintCause, string callChain |
58 | 81 | where |
| 82 | + taintedArg = asSinkExpr(sinkNode.getNode()) and |
59 | 83 | fileFunction.outermostWrapperFunctionCall(taintedArg, callChain) and |
60 | | - taintedWithPath(taintSource, taintedArg, sourceNode, sinkNode) and |
| 84 | + cfg.hasFlowPath(sourceNode, sinkNode) and |
| 85 | + taintSource = asSourceExpr(sourceNode.getNode()) and |
61 | 86 | isUserInput(taintSource, taintCause) |
62 | 87 | select taintedArg, sourceNode, sinkNode, |
63 | 88 | "This argument to a file access function is derived from $@ and then passed to " + callChain + ".", |
|
0 commit comments