Java: Add test.

This commit is contained in:
Anders Schack-Mulligen
2019-08-20 11:17:03 +02:00
parent 5e6326d1d5
commit 6582734733
3 changed files with 48 additions and 0 deletions

View 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);
}
}

View File

@@ -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)] |

View 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