mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
Java: Extend library support for switch expressions.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
class TestSwitchExpr {
|
||||
Object source() { return new Object(); }
|
||||
|
||||
void sink(Object o) { }
|
||||
|
||||
void test(String s) {
|
||||
Object x1 = source();
|
||||
Object x2 = switch (s) {
|
||||
case "a", "b", ("a" + "b") -> null;
|
||||
default -> x1;
|
||||
};
|
||||
Object x3 = switch (s) {
|
||||
case "c", "d" -> { yield x2; }
|
||||
default -> throw new RuntimeException();
|
||||
};
|
||||
Object x4 = switch (s) {
|
||||
case "a", "b":
|
||||
case "c", "d", ("c" + "d"):
|
||||
yield x3;
|
||||
default:
|
||||
throw new RuntimeException();
|
||||
};
|
||||
sink(x4);
|
||||
}
|
||||
}
|
||||
1
java/ql/test/library-tests/dataflow/switchexpr/options
Normal file
1
java/ql/test/library-tests/dataflow/switchexpr/options
Normal file
@@ -0,0 +1 @@
|
||||
//semmle-extractor-options: --javac-args -source 14 -target 14
|
||||
@@ -0,0 +1,9 @@
|
||||
| TestSwitchExpr.java:4:15:4:22 | o |
|
||||
| TestSwitchExpr.java:7:21:7:28 | source(...) |
|
||||
| TestSwitchExpr.java:8:21:8:30 | switch (...) |
|
||||
| TestSwitchExpr.java:10:24:10:25 | x1 |
|
||||
| TestSwitchExpr.java:12:21:12:30 | switch (...) |
|
||||
| TestSwitchExpr.java:13:38:13:39 | x2 |
|
||||
| TestSwitchExpr.java:16:21:16:30 | switch (...) |
|
||||
| TestSwitchExpr.java:19:23:19:24 | x3 |
|
||||
| TestSwitchExpr.java:23:14:23:15 | x4 |
|
||||
@@ -0,0 +1,15 @@
|
||||
import java
|
||||
import semmle.code.java.dataflow.DataFlow
|
||||
import DataFlow
|
||||
|
||||
class Conf extends Configuration {
|
||||
Conf() { this = "qqconf" }
|
||||
|
||||
override predicate isSource(Node n) { n.asExpr().(MethodAccess).getMethod().hasName("source") }
|
||||
|
||||
override predicate isSink(Node n) { any() }
|
||||
}
|
||||
|
||||
from Conf c, Node sink
|
||||
where c.hasFlow(_, sink)
|
||||
select sink
|
||||
Reference in New Issue
Block a user