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() {