Skip to content

Commit 6582734

Browse files
committed
Java: Add test.
1 parent 5e6326d commit 6582734

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public class A {
2+
static void sink(Object o) { }
3+
4+
static class Box {
5+
public Object elem;
6+
}
7+
8+
static Object src() { return new Object(); }
9+
10+
Box f1() {
11+
Box b = new Box();
12+
b.elem = src();
13+
return b;
14+
}
15+
16+
void f2() {
17+
Box b = f1();
18+
f3(b);
19+
}
20+
21+
void f3(Box b) {
22+
Box other = new Box();
23+
sink(other.elem);
24+
}
25+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| 0 | A.java:12:5:12:5 | b [post update] [elem, ... (1)] |
2+
| 0 | A.java:12:5:12:18 | ...=... [Object] |
3+
| 0 | A.java:13:12:13:12 | b [elem, ... (1)] |
4+
| 1 | A.java:17:13:17:16 | f1(...) [elem, ... (1)] |
5+
| 1 | A.java:18:8:18:8 | b [elem, ... (1)] |
6+
| 2 | A.java:21:11:21:15 | b [elem, ... (1)] |
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import java
2+
import semmle.code.java.dataflow.DataFlow
3+
import DataFlow
4+
5+
class Conf extends Configuration {
6+
Conf() { this = "partial flow" }
7+
8+
override predicate isSource(Node n) { n.asExpr().(MethodAccess).getMethod().hasName("src") }
9+
10+
override predicate isSink(Node n) { n.asExpr().(Argument).getCall().getCallee().hasName("sink") }
11+
12+
override int explorationLimit() { result = 10 }
13+
}
14+
15+
from PartialPathNode n, int dist
16+
where any(Conf c).hasPartialFlow(_, n, dist)
17+
select dist, n

0 commit comments

Comments
 (0)