Merge pull request #9229 from tamasvajk/kotlin-df-fix-list

Kotlin: extract non-private members of class supertypes
This commit is contained in:
Tamás Vajk
2022-05-23 14:04:31 +02:00
committed by GitHub
13 changed files with 120 additions and 2160 deletions

View File

@@ -0,0 +1,20 @@
class ListFlowTest {
fun <T> taint(t: T) = t
fun sink(a: Any) {}
fun test(l: MutableList<String>) {
l[0] = taint("a")
sink(l)
sink(l[0])
for (s in l) {
sink(s)
}
val a = arrayOf(taint("a"), "b")
sink(a)
sink(a[0])
for (s in a) {
sink(s)
}
}
}

View File

@@ -0,0 +1,6 @@
| list.kt:6:23:6:23 | a | list.kt:7:14:7:14 | l |
| list.kt:6:23:6:23 | a | list.kt:8:14:8:17 | get(...) |
| list.kt:6:23:6:23 | a | list.kt:10:18:10:18 | s |
| list.kt:13:32:13:32 | a | list.kt:14:14:14:14 | a |
| list.kt:13:32:13:32 | a | list.kt:15:14:15:17 | ...[...] |
| list.kt:13:32:13:32 | a | list.kt:17:18:17:18 | s |

View File

@@ -0,0 +1,19 @@
import java
import semmle.code.java.dataflow.TaintTracking
import semmle.code.java.dataflow.ExternalFlow
class Conf extends TaintTracking::Configuration {
Conf() { this = "qltest:mad-summaries" }
override predicate isSource(DataFlow::Node n) {
n.asExpr().(Argument).getCall().getCallee().hasName("taint")
}
override predicate isSink(DataFlow::Node n) {
n.asExpr().(Argument).getCall().getCallee().hasName("sink")
}
}
from DataFlow::Node src, DataFlow::Node sink, Conf conf
where conf.hasFlow(src, sink)
select src, sink

View File

@@ -0,0 +1,4 @@
test
| file:///modules/java.base/java/util/List.class:0:0:0:0 | iterator | file:///modules/java.base/java/util/Collection.class:0:0:0:0 | iterator |
test1
| file:///modules/java.base/java/util/List.class:0:0:0:0 | iterator |

View File

@@ -0,0 +1,12 @@
import java
query predicate test(Method m1, Method m2) {
m1.getName() = "iterator" and
m1.getDeclaringType().getQualifiedName() = "java.util.List" and
m1.overrides(m2)
}
query predicate test1(Method m1) {
m1.getName() = "iterator" and
m1.getDeclaringType().getQualifiedName() = "java.util.List"
}

View File

@@ -0,0 +1,8 @@
import java.util.List;
import java.util.Arrays;
public final class x {
public final void test() {
List<String> ll = Arrays.asList("a", "b");
}
}

View File

@@ -0,0 +1,4 @@
test
| file:///modules/java.base/java/util/List.class:0:0:0:0 | iterator | file:///modules/java.base/java/util/Collection.class:0:0:0:0 | iterator |
test1
| file:///modules/java.base/java/util/List.class:0:0:0:0 | iterator |

View File

@@ -0,0 +1,12 @@
import java
query predicate test(Method m1, Method m2) {
m1.getName() = "iterator" and
m1.getDeclaringType().getQualifiedName() = "java.util.List" and
m1.overrides(m2)
}
query predicate test1(Method m1) {
m1.getName() = "iterator" and
m1.getDeclaringType().getQualifiedName() = "java.util.List"
}

View File

@@ -0,0 +1,7 @@
import java.util.*
class x {
fun test() {
val ll = Arrays.asList("a", "b")
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -5,13 +5,10 @@ class Foo {
val propInt: Int = 1
val propLong: Long = 1
/*
TODO
val propUByte: UByte = 1u
val propUShort: UShort = 1u
val propUInt: UInt = 1u
val propULong: ULong = 1u
*/
val propFloat: Float = 1.0f
val propDouble: Double = 1.0
@@ -25,14 +22,22 @@ TODO
val propNullableNothing: Nothing? = null
/*
TODO
val propArray: Array<Int> = arrayOf(1, 2, 3)
val propByteArray: ByteArray = byteArrayOf(1, 2, 3)
val propShortArray: ShortArray = shortArrayOf(1, 2, 3)
val propIntArray: IntArray = intArrayOf(1, 2, 3)
val propLongArray: LongArray = longArrayOf(1, 2, 3)
*/
}
class Gen<T> {
fun fn1(a: T) {
val x: Gen<Gen<Int>> = Gen<Gen<Int>>()
class Local<U> {}
val y: Gen<Local<Int>> = Gen<Local<Int>>()
val z = object { }
}
fun fn2(a: Gen<out String>, b: Gen<in String>, c: Gen<in Nothing>, d: Gen<out Any?>) {
}
}

View File

@@ -1,4 +1,8 @@
import java
from Type t
where
t.fromSource()
or
exists(TypeAccess ta | ta.fromSource() and ta.getType() = t)
select t.toString(), concat(t.getAPrimaryQlClass(), ", ")