mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
Revert dataflow changes, extract actual iterator function
This commit is contained in:
committed by
Chris Smowton
parent
538e05995a
commit
fbae0f5053
@@ -1347,6 +1347,23 @@ open class KotlinFileExtractor(
|
||||
return result
|
||||
}
|
||||
|
||||
private fun findTopLevelFunctionOrWarn(functionFilter: String, type: String, warnAgainstElement: IrElement): IrFunction? {
|
||||
|
||||
val fn = pluginContext.referenceFunctions(FqName(functionFilter))
|
||||
.firstOrNull { it.owner.parentClassOrNull?.fqNameWhenAvailable?.asString() == type }
|
||||
?.owner
|
||||
|
||||
if (fn != null) {
|
||||
if (fn.parentClassOrNull != null) {
|
||||
extractExternalClassLater(fn.parentAsClass)
|
||||
}
|
||||
} else {
|
||||
logger.errorElement("Couldn't find JVM intrinsic function $functionFilter in $type", warnAgainstElement)
|
||||
}
|
||||
|
||||
return fn
|
||||
}
|
||||
|
||||
val javaLangString by lazy {
|
||||
val result = pluginContext.referenceClass(FqName("java.lang.String"))?.owner
|
||||
result?.let { extractExternalClassLater(it) }
|
||||
@@ -1860,6 +1877,11 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
}
|
||||
}
|
||||
isFunction(target, "kotlin", "(some array type)", { isArrayType(it) }, "iterator") && c.origin == IrStatementOrigin.FOR_LOOP_ITERATOR -> {
|
||||
findTopLevelFunctionOrWarn("kotlin.jvm.internal.iterator", "kotlin.jvm.internal.ArrayIteratorKt", c)?.let { iteratorFn ->
|
||||
extractRawMethodAccess(iteratorFn, c, callable, parent, idx, enclosingStmt, listOf(c.dispatchReceiver), null, null, listOf((c.dispatchReceiver!!.type as IrSimpleType).arguments.first().typeOrNull!!))
|
||||
}
|
||||
}
|
||||
isFunction(target, "kotlin", "(some array type)", { isArrayType(it) }, "get") && c.origin == IrStatementOrigin.GET_ARRAY_ELEMENT -> {
|
||||
val id = tw.getFreshIdLabel<DbArrayaccess>()
|
||||
val type = useType(c.type)
|
||||
|
||||
@@ -205,11 +205,6 @@ private predicate canContainBool(Type t) {
|
||||
any(BooleanType b).(RefType).getASourceSupertype+() = t
|
||||
}
|
||||
|
||||
private predicate isArray(Type t) {
|
||||
t instanceof Array or
|
||||
t.(RefType).getSourceDeclaration().hasQualifiedName("kotlin", "Array")
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `t1` and `t2` are compatible, that is, whether data can flow from
|
||||
* a node of type `t1` to a node of type `t2`.
|
||||
@@ -226,9 +221,6 @@ predicate compatibleTypes(Type t1, Type t2) {
|
||||
erasedHaveIntersection(e1, e2)
|
||||
or
|
||||
canContainBool(e1) and canContainBool(e2)
|
||||
or
|
||||
// Make java array and `kotlin.Array` types compatible.
|
||||
isArray(e1) and isArray(e2)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@ private import semmle.code.java.dataflow.ExternalFlow
|
||||
|
||||
private class KotlinStdLibSummaryCsv extends SummaryModelCsv {
|
||||
override predicate row(string row) {
|
||||
row = ["kotlin;Array;false;iterator;();;Argument[-1].ArrayElement;ReturnValue.Element;value"]
|
||||
row =
|
||||
[
|
||||
"kotlin.jvm.internal;ArrayIteratorKt;false;iterator;(Object[]);;Argument[0].ArrayElement;ReturnValue.Element;value"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user