Add test for StmtExpr flow

This commit is contained in:
Tony Torralba
2022-02-21 15:40:43 +01:00
committed by Ian Lynagh
parent 8af0f26411
commit b626e80a61
3 changed files with 35 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
class StmtExpr {
fun test() {
val t = object : Source {
override fun a() {
}
}
sink(t) // $ hasValueFlow
}
fun sink(t : Source) {}
}
interface Source {
fun a()
}

View File

@@ -0,0 +1 @@
| StmtExpr.kt:3:17:6:9 | new (...) | StmtExpr.kt:7:14:7:14 | t |

View File

@@ -0,0 +1,18 @@
import java
import semmle.code.java.dataflow.DataFlow
class Conf extends DataFlow::Configuration {
Conf() { this = "qltest:exprStmtFlow" }
override predicate isSource(DataFlow::Node n) {
n.asExpr().(ClassInstanceExpr).getType().(RefType).getASupertype*().hasName("Source")
}
override predicate isSink(DataFlow::Node n) {
n.asExpr().(Argument).getCall().getCallee().hasName("sink")
}
}
from DataFlow::Node src, DataFlow::Node sink, Conf conf
where conf.hasFlow(src, sink)
select src, sink