Skip to content

Commit 538e059

Browse files
tamasvajksmowton
authored andcommitted
Fix dataflow for kotlin.Array.iterator()
1 parent 776322b commit 538e059

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

java/ql/lib/semmle/code/java/dataflow/ExternalFlow.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ private module Frameworks {
143143
private import semmle.code.java.frameworks.JMS
144144
private import semmle.code.java.frameworks.RabbitMQ
145145
private import semmle.code.java.regex.RegexFlowModels
146+
private import semmle.code.java.frameworks.KotlinStdLib
146147
}
147148

148149
private predicate sourceModelCsv(string row) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ private predicate canContainBool(Type t) {
205205
any(BooleanType b).(RefType).getASourceSupertype+() = t
206206
}
207207

208+
private predicate isArray(Type t) {
209+
t instanceof Array or
210+
t.(RefType).getSourceDeclaration().hasQualifiedName("kotlin", "Array")
211+
}
212+
208213
/**
209214
* Holds if `t1` and `t2` are compatible, that is, whether data can flow from
210215
* a node of type `t1` to a node of type `t2`.
@@ -221,6 +226,9 @@ predicate compatibleTypes(Type t1, Type t2) {
221226
erasedHaveIntersection(e1, e2)
222227
or
223228
canContainBool(e1) and canContainBool(e2)
229+
or
230+
// Make java array and `kotlin.Array` types compatible.
231+
isArray(e1) and isArray(e2)
224232
)
225233
}
226234

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/** Definitions of taint steps in the KotlinStdLib framework */
2+
3+
import java
4+
private import semmle.code.java.dataflow.ExternalFlow
5+
6+
private class KotlinStdLibSummaryCsv extends SummaryModelCsv {
7+
override predicate row(string row) {
8+
row = ["kotlin;Array;false;iterator;();;Argument[-1].ArrayElement;ReturnValue.Element;value"]
9+
}
10+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
| C2.kt:8:32:8:32 | a | C2.kt:9:14:9:14 | l |
66
| C2.kt:8:32:8:32 | a | C2.kt:10:14:10:17 | ...[...] |
77
| C2.kt:8:32:8:32 | a | C2.kt:12:18:12:21 | ...[...] |
8+
| C2.kt:8:32:8:32 | a | C2.kt:15:18:15:18 | s |

0 commit comments

Comments
 (0)