Skip to content

Commit 4298a3a

Browse files
committed
Java: Add test.
1 parent f491fcd commit 4298a3a

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class A {
2+
Object customStep(Object o) { return null; }
3+
4+
Object source() { return null; }
5+
6+
void sink(Object o) { }
7+
8+
Object through1(Object o) {
9+
Object o2 = customStep(o);
10+
String s = (String)o2;
11+
return s;
12+
}
13+
14+
void foo() {
15+
Object x = through1(source());
16+
sink(x);
17+
}
18+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| A.java:15:25:15:32 | source(...) | A.java:16:10:16:10 | x | A.java:14:8:14:10 | foo |
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java
2+
import semmle.code.java.dataflow.DataFlow
3+
import DataFlow
4+
5+
class Conf extends Configuration {
6+
Conf() { this = "test types" }
7+
8+
override predicate isSource(Node n) { n.asExpr().(MethodAccess).getMethod().hasName("source") }
9+
10+
override predicate isSink(Node n) {
11+
exists(MethodAccess sink |
12+
sink.getAnArgument() = n.asExpr() and sink.getMethod().hasName("sink")
13+
)
14+
}
15+
16+
override predicate isAdditionalFlowStep(Node n1, Node n2) {
17+
exists(MethodAccess ma |
18+
ma.getMethod().hasName("customStep") and
19+
ma.getAnArgument() = n1.asExpr() and
20+
ma = n2.asExpr()
21+
)
22+
}
23+
}
24+
25+
from Node src, Node sink, Conf conf
26+
where conf.hasFlow(src, sink)
27+
select src, sink, sink.getEnclosingCallable()

0 commit comments

Comments
 (0)