Java: add test case

This commit is contained in:
Asger F
2024-08-20 14:11:44 +02:00
parent bd69b96752
commit 81239dcd95
3 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
public class A {
String field;
static String source(String name) {
return name;
}
static void sink(Object o) {}
static String step(Object o) {
return "";
}
static Object getA() {
A a = new A();
a.field = source("source");
return a;
}
static void test() {
Object object = getA();
sink(step(object)); // $ hasTaintFlow=source
sink(object); // $ SPURIOUS: hasTaintFlow=source
sink(((A)object).field); // $ hasTaintFlow=source
}
}

View File

@@ -0,0 +1,22 @@
import java
import TestUtilities.InlineFlowTest
module TestConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { DefaultFlowConfig::isSource(source) }
predicate isSink(DataFlow::Node sink) { DefaultFlowConfig::isSink(sink) }
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
exists(MethodCall call |
call.getMethod().getName() = "step" and
node1.asExpr() = call.getArgument(0) and
node2.asExpr() = call
)
}
predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet content) {
isAdditionalFlowStep(node, _) and content instanceof DataFlow::FieldContent
}
}
import TaintFlowTest<TestConfig>