From 38ddc064da673715fc87926f495302b4a7119f9f Mon Sep 17 00:00:00 2001 From: "Kunz, Immanuel" Date: Sat, 20 Apr 2024 08:57:46 +0200 Subject: [PATCH] add pass dependencies, initializer check --- .../java/io/clouditor/graph/passes/LabelExtractionPass.kt | 8 ++++---- .../io/clouditor/graph/passes/golang/GolangHttpPass.kt | 7 +++---- .../io/clouditor/graph/passes/golang/GolangLogPass.kt | 2 ++ .../java/io/clouditor/graph/testing/LocalTestingPass.kt | 3 +-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cloudpg/src/main/java/io/clouditor/graph/passes/LabelExtractionPass.kt b/cloudpg/src/main/java/io/clouditor/graph/passes/LabelExtractionPass.kt index 5d21294..705bdcb 100644 --- a/cloudpg/src/main/java/io/clouditor/graph/passes/LabelExtractionPass.kt +++ b/cloudpg/src/main/java/io/clouditor/graph/passes/LabelExtractionPass.kt @@ -160,10 +160,10 @@ class LabelExtractionPass(ctx: TranslationContext) : TranslationResultPass(ctx) ) regexes.entries.forEach { it -> - val matches = it.key.findAll(nodeWComment.comment!!) - if (matches.toList().isNotEmpty()) { - val labels = it.value(nodeWComment, matches) - labels.forEach { + val matches = nodeWComment.comment?.let { it1 -> it.key.findAll(it1) } + if (matches?.toList()?.isNotEmpty() == true) { + val labels = matches?.let { it1 -> it.value(nodeWComment, it1) } + labels?.forEach { t += it // Adding Labels to the supplementary nodes of a translation unit } } diff --git a/cloudpg/src/main/java/io/clouditor/graph/passes/golang/GolangHttpPass.kt b/cloudpg/src/main/java/io/clouditor/graph/passes/golang/GolangHttpPass.kt index 43afc45..d88c48b 100644 --- a/cloudpg/src/main/java/io/clouditor/graph/passes/golang/GolangHttpPass.kt +++ b/cloudpg/src/main/java/io/clouditor/graph/passes/golang/GolangHttpPass.kt @@ -7,6 +7,7 @@ import de.fraunhofer.aisec.cpg.graph.Node import de.fraunhofer.aisec.cpg.graph.declarations.FunctionDeclaration import de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration import de.fraunhofer.aisec.cpg.graph.declarations.VariableDeclaration +import de.fraunhofer.aisec.cpg.graph.firstAssignment import de.fraunhofer.aisec.cpg.graph.statements.expressions.* import de.fraunhofer.aisec.cpg.graph.types.PointerType import de.fraunhofer.aisec.cpg.passes.SymbolResolver @@ -95,10 +96,8 @@ class GolangHttpPass(ctx: TranslationContext) : HttpClientPass(ctx) { ) { // check initializers for http.NewServeMux() // actually check for return types - but that does not work (yet) with the standard library - - if (r.initializer is CallExpression && - (r.initializer as CallExpression).name.toString() == "http.NewServeMux" - ) { + val initializer = r.firstAssignment + if (initializer is CallExpression && initializer.name.toString() == "http.NewServeMux") { val app = result.findApplicationByTU(tu) val requestHandler = HttpRequestHandler(app, mutableListOf(), "/") diff --git a/cloudpg/src/main/java/io/clouditor/graph/passes/golang/GolangLogPass.kt b/cloudpg/src/main/java/io/clouditor/graph/passes/golang/GolangLogPass.kt index e392dc5..c1b0e30 100644 --- a/cloudpg/src/main/java/io/clouditor/graph/passes/golang/GolangLogPass.kt +++ b/cloudpg/src/main/java/io/clouditor/graph/passes/golang/GolangLogPass.kt @@ -7,6 +7,7 @@ import de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration import de.fraunhofer.aisec.cpg.graph.statements.expressions.CallExpression import de.fraunhofer.aisec.cpg.graph.statements.expressions.MemberCallExpression import de.fraunhofer.aisec.cpg.passes.GoExtraPass +import de.fraunhofer.aisec.cpg.passes.SymbolResolver import de.fraunhofer.aisec.cpg.passes.order.DependsOn import de.fraunhofer.aisec.cpg.processing.IVisitor import de.fraunhofer.aisec.cpg.processing.strategy.Strategy @@ -14,6 +15,7 @@ import io.clouditor.graph.passes.LogPass import kotlin.streams.toList @DependsOn(GoExtraPass::class) +@DependsOn(SymbolResolver::class) class GolangLogPass(ctx: TranslationContext) : LogPass(ctx) { override fun accept(result: TranslationResult) { val translationUnits = diff --git a/cloudpg/src/main/java/io/clouditor/graph/testing/LocalTestingPass.kt b/cloudpg/src/main/java/io/clouditor/graph/testing/LocalTestingPass.kt index a8510a7..9c6cc29 100644 --- a/cloudpg/src/main/java/io/clouditor/graph/testing/LocalTestingPass.kt +++ b/cloudpg/src/main/java/io/clouditor/graph/testing/LocalTestingPass.kt @@ -49,8 +49,7 @@ class LocalTestingPass(ctx: TranslationContext) : TranslationResultPass(ctx) { } private fun handleConf(conf: TestConfig, t: TranslationResult) { - val controllers = - t.additionalNodes.filter { it is HttpRequestHandler }.map { it as HttpRequestHandler } + val controllers = t.additionalNodes.filterIsInstance() for (service in conf.services) { if (service.type == "server" || service.type == "third-party") {