From a017f3975ca7bf754e592cad76e85c8794957aec Mon Sep 17 00:00:00 2001 From: Alexander Kuechler Date: Tue, 12 Mar 2024 16:52:34 +0100 Subject: [PATCH] Re-add connector method if ControlFlowSensitiveDFG is not executed --- .../de/fraunhofer/aisec/cpg/passes/DFGPass.kt | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/DFGPass.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/DFGPass.kt index 47cf7ae892..f4d0ec0bf7 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/DFGPass.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/DFGPass.kt @@ -51,6 +51,34 @@ class DFGPass(ctx: TranslationContext) : ComponentPass(ctx) { for (tu in component.translationUnits) { walker.iterate(tu) } + if (config.registeredPasses.any { ControlFlowSensitiveDFGPass::class !in it }) { + connectInferredCallArguments(config.functionSummaries) + } + } + + /** + * For inferred functions which have function summaries encoded, we connect the arguments to + * modified parameter to propagate the changes to the arguments out of the [FunctionDeclaration] + * again. + */ + private fun connectInferredCallArguments(functionSummaries: DFGFunctionSummaries) { + for (call in callsInferredFunctions) { + for (invoked in call.invokes.filter { it.isInferred }) { + val changedParams = + functionSummaries.functionToChangedParameters[invoked] ?: mapOf() + for ((param, _) in changedParams) { + if (param == (invoked as? MethodDeclaration)?.receiver) { + (call as? MemberCallExpression) + ?.base + ?.addPrevDFGContext(param, CallingContextOut(call)) + } else if (param is ParameterDeclaration) { + val arg = call.arguments[param.argumentIndex] + arg.addPrevDFGContext(param, CallingContextOut(call)) + // (arg as? Reference)?.access = AccessValues.READWRITE + } + } + } + } } override fun cleanup() {