|
14 | 14 |
|
15 | 15 | import cpp
|
16 | 16 | import semmle.code.cpp.security.Security
|
| 17 | +import semmle.code.cpp.security.FlowSources |
17 | 18 | import semmle.code.cpp.security.FunctionWithWrappers
|
18 |
| -import semmle.code.cpp.ir.dataflow.internal.DefaultTaintTrackingImpl |
19 |
| -import TaintedWithPath |
| 19 | +import semmle.code.cpp.ir.IR |
| 20 | +import semmle.code.cpp.ir.dataflow.TaintTracking |
20 | 21 |
|
21 | 22 | class SqlLikeFunction extends FunctionWithWrappers {
|
22 | 23 | SqlLikeFunction() { sqlArgument(this.getName(), _) }
|
23 | 24 |
|
24 | 25 | override predicate interestingArg(int arg) { sqlArgument(this.getName(), arg) }
|
25 | 26 | }
|
26 | 27 |
|
27 |
| -class Configuration extends TaintTrackingConfiguration { |
28 |
| - override predicate isSink(Element tainted) { |
29 |
| - exists(SqlLikeFunction runSql | runSql.outermostWrapperFunctionCall(tainted, _)) |
| 28 | +Expr asSinkExpr(DataFlow::Node node) { |
| 29 | + result = node.asIndirectArgument() |
| 30 | + or |
| 31 | + // We want the conversion so we only get one node for the expression |
| 32 | + result = node.asConvertedExpr() |
| 33 | +} |
| 34 | + |
| 35 | +module SqlTaintedConfig implements DataFlow::ConfigSig { |
| 36 | + predicate isSource(DataFlow::Node node) { node instanceof FlowSource } |
| 37 | + |
| 38 | + predicate isSink(DataFlow::Node node) { |
| 39 | + exists(SqlLikeFunction runSql | runSql.outermostWrapperFunctionCall(asSinkExpr(node), _)) |
30 | 40 | }
|
31 | 41 |
|
32 |
| - override predicate isBarrier(Expr e) { |
33 |
| - super.isBarrier(e) |
34 |
| - or |
35 |
| - e.getUnspecifiedType() instanceof IntegralType |
36 |
| - or |
| 42 | + predicate isBarrier(DataFlow::Node node) { |
| 43 | + node.asExpr().getUnspecifiedType() instanceof IntegralType |
| 44 | + } |
| 45 | + |
| 46 | + predicate isBarrierIn(DataFlow::Node node) { |
37 | 47 | exists(SqlBarrierFunction sql, int arg, FunctionInput input |
|
38 |
| - e = sql.getACallToThisFunction().getArgument(arg) and |
| 48 | + node.asIndirectArgument() = sql.getACallToThisFunction().getArgument(arg) and |
39 | 49 | input.isParameterDeref(arg) and
|
40 | 50 | sql.barrierSqlArgument(input, _)
|
41 | 51 | )
|
42 | 52 | }
|
43 | 53 | }
|
44 | 54 |
|
| 55 | +module SqlTainted = TaintTracking::Global<SqlTaintedConfig>; |
| 56 | + |
| 57 | +import SqlTainted::PathGraph |
| 58 | + |
45 | 59 | from
|
46 |
| - SqlLikeFunction runSql, Expr taintedArg, Expr taintSource, PathNode sourceNode, PathNode sinkNode, |
47 |
| - string taintCause, string callChain |
| 60 | + SqlLikeFunction runSql, Expr taintedArg, FlowSource taintSource, SqlTainted::PathNode sourceNode, |
| 61 | + SqlTainted::PathNode sinkNode, string callChain |
48 | 62 | where
|
49 | 63 | runSql.outermostWrapperFunctionCall(taintedArg, callChain) and
|
50 |
| - taintedWithPath(taintSource, taintedArg, sourceNode, sinkNode) and |
51 |
| - isUserInput(taintSource, taintCause) |
| 64 | + SqlTainted::flowPath(sourceNode, sinkNode) and |
| 65 | + taintedArg = asSinkExpr(sinkNode.getNode()) and |
| 66 | + taintSource = sourceNode.getNode() |
52 | 67 | select taintedArg, sourceNode, sinkNode,
|
53 | 68 | "This argument to a SQL query function is derived from $@ and then passed to " + callChain + ".",
|
54 |
| - taintSource, "user input (" + taintCause + ")" |
| 69 | + taintSource, "user input (" + taintSource.getSourceType() + ")" |
0 commit comments