mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Java: Add test.
This commit is contained in:
25
java/ql/test/library-tests/dataflow/partial/A.java
Normal file
25
java/ql/test/library-tests/dataflow/partial/A.java
Normal file
@@ -0,0 +1,25 @@
|
||||
public class A {
|
||||
static void sink(Object o) { }
|
||||
|
||||
static class Box {
|
||||
public Object elem;
|
||||
}
|
||||
|
||||
static Object src() { return new Object(); }
|
||||
|
||||
Box f1() {
|
||||
Box b = new Box();
|
||||
b.elem = src();
|
||||
return b;
|
||||
}
|
||||
|
||||
void f2() {
|
||||
Box b = f1();
|
||||
f3(b);
|
||||
}
|
||||
|
||||
void f3(Box b) {
|
||||
Box other = new Box();
|
||||
sink(other.elem);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
| 0 | A.java:12:5:12:5 | b [post update] [elem, ... (1)] |
|
||||
| 0 | A.java:12:5:12:18 | ...=... [Object] |
|
||||
| 0 | A.java:13:12:13:12 | b [elem, ... (1)] |
|
||||
| 1 | A.java:17:13:17:16 | f1(...) [elem, ... (1)] |
|
||||
| 1 | A.java:18:8:18:8 | b [elem, ... (1)] |
|
||||
| 2 | A.java:21:11:21:15 | b [elem, ... (1)] |
|
||||
17
java/ql/test/library-tests/dataflow/partial/test.ql
Normal file
17
java/ql/test/library-tests/dataflow/partial/test.ql
Normal file
@@ -0,0 +1,17 @@
|
||||
import java
|
||||
import semmle.code.java.dataflow.DataFlow
|
||||
import DataFlow
|
||||
|
||||
class Conf extends Configuration {
|
||||
Conf() { this = "partial flow" }
|
||||
|
||||
override predicate isSource(Node n) { n.asExpr().(MethodAccess).getMethod().hasName("src") }
|
||||
|
||||
override predicate isSink(Node n) { n.asExpr().(Argument).getCall().getCallee().hasName("sink") }
|
||||
|
||||
override int explorationLimit() { result = 10 }
|
||||
}
|
||||
|
||||
from PartialPathNode n, int dist
|
||||
where any(Conf c).hasPartialFlow(_, n, dist)
|
||||
select dist, n
|
||||
Reference in New Issue
Block a user