mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Kotlin: Support apply
This commit is contained in:
4
java/ql/lib/change-notes/2023-07-10-kotlin-apply.md
Normal file
4
java/ql/lib/change-notes/2023-07-10-kotlin-apply.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
* Added support for the Kotlin method `apply`.
|
||||
@@ -3,5 +3,7 @@ extensions:
|
||||
pack: codeql/java-all
|
||||
extensible: summaryModel
|
||||
data:
|
||||
- ["kotlin", "StandardKt", False, "apply", "", "", "Argument[0]", "Argument[1].Parameter[0]", "value", "manual"]
|
||||
- ["kotlin", "StandardKt", False, "apply", "", "", "Argument[0]", "ReturnValue", "value", "manual"]
|
||||
- ["kotlin", "StandardKt", False, "with", "", "", "Argument[0]", "Argument[1].Parameter[0]", "value", "manual"]
|
||||
- ["kotlin", "StandardKt", False, "with", "", "", "Argument[1].ReturnValue", "ReturnValue", "value", "manual"]
|
||||
|
||||
21
java/ql/lib/semmle/code/java/frameworks/kotlin/Kotlin.qll
Normal file
21
java/ql/lib/semmle/code/java/frameworks/kotlin/Kotlin.qll
Normal file
@@ -0,0 +1,21 @@
|
||||
/** Provides classes and predicates related to `kotlin`. */
|
||||
|
||||
import java
|
||||
|
||||
/** A call to Kotlin's `apply` method. */
|
||||
class KotlinApply extends MethodAccess {
|
||||
ExtensionMethod m;
|
||||
|
||||
KotlinApply() {
|
||||
this.getMethod() = m and
|
||||
m.hasQualifiedName("kotlin", "StandardKt", "apply")
|
||||
}
|
||||
|
||||
/** Gets the function block argument of this call. */
|
||||
LambdaExpr getLambdaArg() {
|
||||
result = this.getArgument(m.getExtensionReceiverParameterIndex() + 1)
|
||||
}
|
||||
|
||||
/** Gets the receiver argument of this call. */
|
||||
Argument getReceiver() { result = this.getArgument(m.getExtensionReceiverParameterIndex()) }
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
| apply.kt:6:9:6:41 | apply(...) |
|
||||
| apply.kt:7:14:7:40 | apply(...) |
|
||||
@@ -0,0 +1,9 @@
|
||||
class ApplyFlowTest {
|
||||
fun <T> taint(t: T) = t
|
||||
fun sink(s: String) { }
|
||||
|
||||
fun test(input: String) {
|
||||
taint(input).apply { sink(this) } // $ hasValueFlow
|
||||
sink(taint(input).apply { this }) // $ hasValueFlow
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import java
|
||||
import semmle.code.java.frameworks.kotlin.Kotlin
|
||||
|
||||
from KotlinApply a
|
||||
select a
|
||||
Reference in New Issue
Block a user