mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
Java: Add test.
This commit is contained in:
18
java/ql/test/library-tests/dataflow/typepruning/A.java
Normal file
18
java/ql/test/library-tests/dataflow/typepruning/A.java
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
| A.java:15:25:15:32 | source(...) | A.java:16:10:16:10 | x | A.java:14:8:14:10 | foo |
|
||||
27
java/ql/test/library-tests/dataflow/typepruning/test.ql
Normal file
27
java/ql/test/library-tests/dataflow/typepruning/test.ql
Normal 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()
|
||||
Reference in New Issue
Block a user