Skip to content

Commit

Permalink
add pass dependencies, initializer check
Browse files Browse the repository at this point in the history
  • Loading branch information
immqu committed Apr 20, 2024
1 parent 7dc76c1 commit 38ddc06
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(), "/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ 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
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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpRequestHandler>()

for (service in conf.services) {
if (service.type == "server" || service.type == "third-party") {
Expand Down

0 comments on commit 38ddc06

Please sign in to comment.