mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
Add test for a pattern-switch guard acting as a data-flow guard
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
| GuardTest.java:6:27:6:34 | o | GuardTest.java:11:14:11:14 | s |
|
||||
| Test.java:11:23:11:25 | "A" | Test.java:15:14:15:20 | get(...) |
|
||||
| Test.java:11:23:11:25 | "A" | Test.java:25:24:25:30 | get(...) |
|
||||
| Test.java:11:23:11:25 | "A" | Test.java:32:20:32:26 | get(...) |
|
||||
|
||||
@@ -1,11 +1,24 @@
|
||||
import java
|
||||
|
||||
import semmle.code.java.controlflow.Guards
|
||||
import semmle.code.java.dataflow.DataFlow
|
||||
|
||||
private predicate isSafe(Guard g, Expr checked, boolean branch) {
|
||||
exists(MethodCall mc | g = mc |
|
||||
mc.getMethod().hasName("isSafe") and
|
||||
checked = mc.getAnArgument() and
|
||||
branch = true
|
||||
)
|
||||
}
|
||||
|
||||
module TestConfig implements DataFlow::ConfigSig {
|
||||
predicate isSource(DataFlow::Node source) { source.asExpr() instanceof StringLiteral }
|
||||
predicate isSource(DataFlow::Node source) { source.asExpr() instanceof StringLiteral or source.asParameter().getCallable().hasName("test") }
|
||||
|
||||
predicate isSink(DataFlow::Node sink) { sink.asExpr() = any(MethodCall mc | mc.getMethod().getName() = "sink").getAnArgument() }
|
||||
|
||||
predicate isBarrier(DataFlow::Node node) {
|
||||
node = DataFlow::BarrierGuard<isSafe/3>::getABarrierNode()
|
||||
}
|
||||
}
|
||||
|
||||
module Flow = DataFlow::Global<TestConfig>;
|
||||
|
||||
Reference in New Issue
Block a user