From 43ffd46305912c84a576096e7824a035ea816bca Mon Sep 17 00:00:00 2001 From: Alexander Kuechler Date: Mon, 18 Mar 2024 10:02:28 +0100 Subject: [PATCH] test coverage++ --- .../cpg/passes/ControlFlowSensitiveDFGPass.kt | 36 +++++++++++-------- .../enhancements/DFGFunctionSummariesTest.kt | 7 +++- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ControlFlowSensitiveDFGPass.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ControlFlowSensitiveDFGPass.kt index 35588bbc74..cf9ab92dc5 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ControlFlowSensitiveDFGPass.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ControlFlowSensitiveDFGPass.kt @@ -391,24 +391,32 @@ open class ControlFlowSensitiveDFGPass(ctx: TranslationContext) : EOGStarterPass PowersetLattice(identitySetOf(currentNode)) ) } else if (currentNode is CallExpression) { - for (invoked in + val functionsWithSummaries = currentNode.invokes.filter { it in ctx.config.functionSummaries.functionToChangedParameters - }) { - val changedParams = - ctx.config.functionSummaries.functionToChangedParameters[invoked] ?: mapOf() - for ((param, _) in changedParams) { - if (param == (invoked as? MethodDeclaration)?.receiver) { - doubleState.declarationsState[ - ((currentNode as? MemberCallExpression)?.base as? Reference) - ?.refersTo] = PowersetLattice(identitySetOf(param)) - } else if (param is ParameterDeclaration) { - val arg = currentNode.arguments[param.argumentIndex] - doubleState.declarationsState[(arg as? Reference)?.refersTo] = - PowersetLattice(identitySetOf(param)) + } + if (functionsWithSummaries.isNotEmpty()) { + for (invoked in functionsWithSummaries) { + val changedParams = + ctx.config.functionSummaries.functionToChangedParameters[invoked] ?: mapOf() + for ((param, _) in changedParams) { + if (param == (invoked as? MethodDeclaration)?.receiver) { + doubleState.declarationsState[ + ((currentNode as? MemberCallExpression)?.base as? Reference) + ?.refersTo] = PowersetLattice(identitySetOf(param)) + } else if (param is ParameterDeclaration) { + val arg = currentNode.arguments[param.argumentIndex] + doubleState.declarationsState[(arg as? Reference)?.refersTo] = + PowersetLattice(identitySetOf(param)) + } + edgePropertiesMap[param] = CallingContextOut(currentNode) } - edgePropertiesMap[param] = CallingContextOut(currentNode) } + } else { + doubleState.declarationsState.push( + currentNode, + doubleState.declarationsState[currentEdge.start] + ) } } else { doubleState.declarationsState.push( diff --git a/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/enhancements/DFGFunctionSummariesTest.kt b/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/enhancements/DFGFunctionSummariesTest.kt index 9afa3b3022..911cf1f7e5 100644 --- a/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/enhancements/DFGFunctionSummariesTest.kt +++ b/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/enhancements/DFGFunctionSummariesTest.kt @@ -145,10 +145,15 @@ class DFGFunctionSummariesTest { construct("test.Object") } - memberCall("addAll", construct("test.List")) { + declare { + variable("a", t("test.List")) { construct("test.List") } + } + + memberCall("addAll", ref("a", t("test.List"))) { literal(1, t("int")) construct("test.Object") } + call("print") { ref("a", t("test.List")) } memberCall("addAll", construct("random.Type")) { literal(1, t("int"))