|
| 1 | +/** |
| 2 | + * @kind path-problem |
| 3 | + */ |
| 4 | + |
| 5 | +import swift |
| 6 | +import codeql.swift.dataflow.TaintTracking |
| 7 | +import codeql.swift.dataflow.DataFlow::DataFlow |
| 8 | +import TestUtilities.InlineExpectationsTest |
| 9 | + |
| 10 | +class TestConfiguration extends TaintTracking::Configuration { |
| 11 | + TestConfiguration() { this = "TestConfiguration" } |
| 12 | + |
| 13 | + override predicate isSource(Node src) { |
| 14 | + src.asExpr().(CallExpr).getStaticTarget().getName().matches("source%") |
| 15 | + } |
| 16 | + |
| 17 | + override predicate isSink(Node sink) { |
| 18 | + exists(CallExpr sinkCall | |
| 19 | + sinkCall.getStaticTarget().getName().matches("sink%") and |
| 20 | + sinkCall.getAnArgument().getExpr() = sink.asExpr() |
| 21 | + ) |
| 22 | + } |
| 23 | + |
| 24 | + override int explorationLimit() { result = 100 } |
| 25 | +} |
| 26 | + |
| 27 | +class TaintTest extends InlineExpectationsTest { |
| 28 | + TaintTest() { this = "taintedFromLine" } |
| 29 | + |
| 30 | + override string getARelevantTag() { result = "taintedFromLine" } |
| 31 | + |
| 32 | + override predicate hasActualResult(Location location, string element, string tag, string value) { |
| 33 | + exists(TestConfiguration config, Node source, Node sink, Expr sinkExpr | |
| 34 | + config.hasFlow(source, sink) and |
| 35 | + sinkExpr = sink.asExpr() and |
| 36 | + location = sinkExpr.getLocation() and |
| 37 | + element = sinkExpr.toString() and |
| 38 | + tag = "taintedFromLine" and |
| 39 | + value = source.asExpr().getLocation().getStartLine().toString() |
| 40 | + ) |
| 41 | + } |
| 42 | +} |
0 commit comments