Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8406ee7

Browse files
committed
Add test for a pattern-switch guard acting as a data-flow guard
1 parent 144218e commit 8406ee7

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

java/ql/test/library-tests/pattern-switch/dfg/test.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| GuardTest.java:6:27:6:34 | o | GuardTest.java:11:14:11:14 | s |
12
| Test.java:11:23:11:25 | "A" | Test.java:15:14:15:20 | get(...) |
23
| Test.java:11:23:11:25 | "A" | Test.java:25:24:25:30 | get(...) |
34
| Test.java:11:23:11:25 | "A" | Test.java:32:20:32:26 | get(...) |

java/ql/test/library-tests/pattern-switch/dfg/test.ql

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
import java
22

3+
import semmle.code.java.controlflow.Guards
34
import semmle.code.java.dataflow.DataFlow
45

6+
private predicate isSafe(Guard g, Expr checked, boolean branch) {
7+
exists(MethodCall mc | g = mc |
8+
mc.getMethod().hasName("isSafe") and
9+
checked = mc.getAnArgument() and
10+
branch = true
11+
)
12+
}
13+
514
module TestConfig implements DataFlow::ConfigSig {
6-
predicate isSource(DataFlow::Node source) { source.asExpr() instanceof StringLiteral }
15+
predicate isSource(DataFlow::Node source) { source.asExpr() instanceof StringLiteral or source.asParameter().getCallable().hasName("test") }
716

817
predicate isSink(DataFlow::Node sink) { sink.asExpr() = any(MethodCall mc | mc.getMethod().getName() = "sink").getAnArgument() }
18+
19+
predicate isBarrier(DataFlow::Node node) {
20+
node = DataFlow::BarrierGuard<isSafe/3>::getABarrierNode()
21+
}
922
}
1023

1124
module Flow = DataFlow::Global<TestConfig>;

0 commit comments

Comments
 (0)