Skip to content

Commit 7833de1

Browse files
committed
Merge branch 'main' into rdmarsh2/cpp/product-flow
2 parents 011d15a + e174123 commit 7833de1

File tree

35 files changed

+6759
-119
lines changed

35 files changed

+6759
-119
lines changed

cpp/ql/lib/experimental/semmle/code/cpp/semantic/SemanticExprSpecific.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ module SemanticExprConfig {
162162
predicate phi(SsaVariable v) { v.asInstruction() instanceof IR::PhiInstruction }
163163

164164
SsaVariable getAPhiInput(SsaVariable v) {
165-
exists(IR::PhiInstruction instr |
165+
exists(IR::PhiInstruction instr | v.asInstruction() = instr |
166166
result.asInstruction() = instr.getAnInput()
167167
or
168168
result.asOperand() = instr.getAnInputOperand()

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2394,7 +2394,11 @@ open class KotlinFileExtractor(
23942394
if (e.typeArgumentsCount > 0) {
23952395
logger.warnElement("Unexpected type arguments (${e.typeArgumentsCount}) for anonymous class constructor call", e)
23962396
}
2397-
val c = eType.classifier.owner as IrClass
2397+
val c = eType.classifier.owner
2398+
if (c !is IrClass) {
2399+
logger.errorElement("Anonymous constructor call type not a class (${c.javaClass})", e)
2400+
return
2401+
}
23982402
useAnonymousClass(c)
23992403
} else {
24002404
useType(eType)
@@ -4260,6 +4264,8 @@ open class KotlinFileExtractor(
42604264
* Extracts a type access expression and its child type access expressions in case of a generic type. Nested generics are also handled.
42614265
*/
42624266
private fun extractTypeAccessRecursive(t: IrType, location: Label<DbLocation>, parent: Label<out DbExprparent>, idx: Int, enclosingCallable: Label<out DbCallable>, enclosingStmt: Label<out DbStmt>, typeContext: TypeContext = TypeContext.OTHER): Label<out DbExpr> {
4267+
// TODO: `useType` substitutes types to their java equivalent, and sometimes that also means changing the number of type arguments. The below logic doesn't take this into account.
4268+
// For example `KFunction2<Int,Double,String>` becomes `KFunction<String>` with three child type access expressions: `Int`, `Double`, `String`.
42634269
val typeAccessId = extractTypeAccess(useType(t, typeContext), location, parent, idx, enclosingCallable, enclosingStmt)
42644270
if (t is IrSimpleType) {
42654271
extractTypeArguments(t.arguments.filterIsInstance<IrType>(), location, typeAccessId, enclosingCallable, enclosingStmt)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added flow sinks, sources and summaries for the Kotlin standard library.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private module Frameworks {
153153
private import semmle.code.java.frameworks.JMS
154154
private import semmle.code.java.frameworks.RabbitMQ
155155
private import semmle.code.java.regex.RegexFlowModels
156-
private import semmle.code.java.frameworks.KotlinStdLib
156+
private import semmle.code.java.frameworks.kotlin.StdLib
157157
}
158158

159159
/**

java/ql/lib/semmle/code/java/frameworks/KotlinStdLib.qll

Lines changed: 0 additions & 11 deletions
This file was deleted.

java/ql/lib/semmle/code/java/frameworks/generated.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ import java
66

77
private module GeneratedFrameworks {
88
private import apache.IOGenerated
9+
private import kotlin.StdLibGenerated
910
}

java/ql/lib/semmle/code/java/frameworks/kotlin/NegativeStdLibGenerated.qll

Lines changed: 4414 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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 =
9+
[
10+
"kotlin.jvm.internal;ArrayIteratorKt;false;iterator;(Object[]);;Argument[0].ArrayElement;ReturnValue.Element;value;manual",
11+
"kotlin.collections;ArraysKt;false;withIndex;(Object[]);;Argument[0].ArrayElement;ReturnValue;taint;manual"
12+
]
13+
}
14+
}

java/ql/lib/semmle/code/java/frameworks/kotlin/StdLibGenerated.qll

Lines changed: 1868 additions & 0 deletions
Large diffs are not rendered by default.

java/ql/test/kotlin/library-tests/dataflow/summaries/list.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ class ListFlowTest {
44

55
fun test(l: MutableList<String>) {
66
l[0] = taint("a")
7-
sink(l)
8-
sink(l[0])
7+
sink(l) // $ hasTaintFlow=a
8+
sink(l[0]) // $ hasValueFlow=a
99
for (s in l) {
10-
sink(s)
10+
sink(s) // $ hasValueFlow=a
1111
}
1212

13-
val a = arrayOf(taint("a"), "b")
14-
sink(a)
15-
sink(a[0])
13+
val a = arrayOf(taint("b"), "c")
14+
sink(a) // $ hasTaintFlow=b
15+
sink(a[0]) // $ hasValueFlow=b
1616
for (s in a) {
17-
sink(s)
17+
sink(s) // $ hasValueFlow=b
1818
}
1919
}
2020
}

0 commit comments

Comments
 (0)