Skip to content

Commit c1cc441

Browse files
authored
Merge pull request github#15023 from igfoo/igfoo/df-wrapper
Kotlin: Fix dataflow with Array.set wrappers
2 parents faa63dd + fc11a87 commit c1cc441

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

java/ql/lib/semmle/code/java/dataflow/internal/ContainerFlow.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ predicate arrayStoreStep(Node node1, Node node2) {
452452
)
453453
or
454454
exists(Expr arr, Call call |
455-
arr = node2.asExpr() and
455+
arr = node2.(PostUpdateNode).getPreUpdateNode().asExpr() and
456456
call.getArgument(1) = node1.asExpr() and
457457
call.getQualifier() = arr and
458458
arr.getType() instanceof ArrayType and

java/ql/test-kotlin1/library-tests/dataflow/foreach/C2.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,14 @@ class C2 {
2727
sink(l1.get(0))
2828
sink(l2.get(0))
2929
}
30+
31+
fun setWrapper(l: Array<String>, v: String) {
32+
l.set(0, v)
33+
}
34+
fun test3() {
35+
val l = arrayOf("")
36+
setWrapper(l, taint("a"))
37+
sink(l[0])
38+
sink(l.get(0))
39+
}
3040
}

java/ql/test-kotlin1/library-tests/dataflow/foreach/test.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
| C2.kt:23:24:23:24 | "a" | C2.kt:27:14:27:22 | get(...) |
1212
| C2.kt:24:26:24:26 | "a" | C2.kt:26:14:26:18 | ...[...] |
1313
| C2.kt:24:26:24:26 | "a" | C2.kt:28:14:28:22 | get(...) |
14+
| C2.kt:36:30:36:30 | "a" | C2.kt:37:14:37:17 | ...[...] |
15+
| C2.kt:36:30:36:30 | "a" | C2.kt:38:14:38:21 | get(...) |

0 commit comments

Comments
 (0)