Skip to content

Commit e4084d7

Browse files
Kotlin: test name-based destructuring
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 054aab2 commit e4084d7

4 files changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
selectedProperty
2+
| test.kt:10:10:10:17 | currency | test.kt:10:10:10:17 | getCurrency(...) | test.kt:3:36:3:55 | getCurrency |
3+
#select
4+
| test.kt:14:28:14:35 | source(...) | test.kt:11:10:11:17 | currency |
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// codeql-extractor-kotlin-options: -XXLanguage:+FullValueClasses -XXLanguage:+NameBasedDestructuring -XXLanguage:+EnableNameBasedDestructuringShortForm
2+
3+
value class Money(val amount: Int, val currency: String)
4+
5+
fun source(): String = ""
6+
7+
fun sink(value: String) {}
8+
9+
fun test(money: Money) {
10+
val (currency) = money
11+
sink(currency)
12+
}
13+
14+
fun flow() = test(Money(0, source()))
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import java
2+
import semmle.code.java.dataflow.TaintTracking
3+
4+
query predicate selectedProperty(
5+
LocalVariableDeclExpr variable, MethodCall initializer, Method getter
6+
) {
7+
variable.getVariable().hasName("currency") and
8+
initializer = variable.getInit() and
9+
getter = initializer.getMethod()
10+
}
11+
12+
module Config implements DataFlow::ConfigSig {
13+
predicate isSource(DataFlow::Node n) { n.asExpr().(MethodCall).getMethod().hasName("source") }
14+
15+
predicate isSink(DataFlow::Node n) { n.asExpr().(Argument).getCall().getCallee().hasName("sink") }
16+
}
17+
18+
module Flow = TaintTracking::Global<Config>;
19+
20+
from DataFlow::Node source, DataFlow::Node sink
21+
where Flow::flow(source, sink)
22+
select source, sink
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.ql

0 commit comments

Comments
 (0)