Kotlin: Add flow through use and with

This commit is contained in:
Tony Torralba
2023-06-06 11:22:16 +02:00
parent 6c5c338e6b
commit 72af634575
4 changed files with 29 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
import java.io.Closeable
class UseFlowTest {
fun <T> taint(t: T) = t
fun sink(s: Closeable) { }
fun test(input: Closeable) {
taint(input).use { it -> sink(it) } // $ hasValueFlow
sink(taint(input).use { it }) // $ hasValueFlow
}
}

View File

@@ -0,0 +1,9 @@
class WithFlowTest {
fun <T> taint(t: T) = t
fun sink(s: String) { }
fun test(input: String) {
with(taint(input)) { sink(this) } // $ hasValueFlow
sink(with(taint(input)) { this }) // $ hasValueFlow
}
}