Java: Add test.

This commit is contained in:
Anders Schack-Mulligen
2020-03-09 11:16:59 +01:00
parent f491fcd5ae
commit 4298a3a931
3 changed files with 46 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
public class A {
Object customStep(Object o) { return null; }
Object source() { return null; }
void sink(Object o) { }
Object through1(Object o) {
Object o2 = customStep(o);
String s = (String)o2;
return s;
}
void foo() {
Object x = through1(source());
sink(x);
}
}

View File

@@ -0,0 +1 @@
| A.java:15:25:15:32 | source(...) | A.java:16:10:16:10 | x | A.java:14:8:14:10 | foo |

View File

@@ -0,0 +1,27 @@
import java
import semmle.code.java.dataflow.DataFlow
import DataFlow
class Conf extends Configuration {
Conf() { this = "test types" }
override predicate isSource(Node n) { n.asExpr().(MethodAccess).getMethod().hasName("source") }
override predicate isSink(Node n) {
exists(MethodAccess sink |
sink.getAnArgument() = n.asExpr() and sink.getMethod().hasName("sink")
)
}
override predicate isAdditionalFlowStep(Node n1, Node n2) {
exists(MethodAccess ma |
ma.getMethod().hasName("customStep") and
ma.getAnArgument() = n1.asExpr() and
ma = n2.asExpr()
)
}
}
from Node src, Node sink, Conf conf
where conf.hasFlow(src, sink)
select src, sink, sink.getEnclosingCallable()