Files
codeql/java/ql/test/kotlin/library-tests/parameter-defaults/flowTest.ql
Chris Smowton 34a0a0d080 Implement $default method synthesis
This adds methods that fill in default parameters whenever a constructor or method uses default parameter values. I use as similar an approach to the real Kotlin compiler as possible both because this produces the desirable dataflow, and because it should merge cleanly with the same class file seen by the Java extractor, which will see and
extract the signatures of the default methods.
2022-10-06 12:38:55 +01:00

35 lines
935 B
Plaintext

import java
import semmle.code.java.dataflow.DataFlow
class ShouldNotBeSunk extends StringLiteral {
ShouldNotBeSunk() { this.getValue().matches("%not sunk%") }
}
class ShouldBeSunk extends StringLiteral {
ShouldBeSunk() {
this.getValue().matches("%sunk%") and
not this instanceof ShouldNotBeSunk
}
}
class Config extends DataFlow::Configuration {
Config() { this = "Config" }
override predicate isSource(DataFlow::Node n) {
n.asExpr() instanceof ShouldBeSunk or
n.asExpr() instanceof ShouldNotBeSunk
}
override predicate isSink(DataFlow::Node n) {
n.asExpr().(Argument).getCall().getCallee().getName() = "sink"
}
}
predicate isSunk(StringLiteral sl) {
exists(Config c, DataFlow::Node source | c.hasFlow(source, _) and sl = source.asExpr())
}
query predicate shouldBeSunkButIsnt(ShouldBeSunk src) { not isSunk(src) }
query predicate shouldntBeSunkButIs(ShouldNotBeSunk src) { isSunk(src) }