diff --git a/dataflowengineoss/src/main/scala/io/joern/dataflowengineoss/passes/reachingdef/DdgGenerator.scala b/dataflowengineoss/src/main/scala/io/joern/dataflowengineoss/passes/reachingdef/DdgGenerator.scala index 887531648c7e..cabd66378a0a 100644 --- a/dataflowengineoss/src/main/scala/io/joern/dataflowengineoss/passes/reachingdef/DdgGenerator.scala +++ b/dataflowengineoss/src/main/scala/io/joern/dataflowengineoss/passes/reachingdef/DdgGenerator.scala @@ -1,12 +1,13 @@ package io.joern.dataflowengineoss.passes.reachingdef -import io.joern.dataflowengineoss.{globalFromLiteral, identifierToFirstUsages} import io.joern.dataflowengineoss.queryengine.AccessPathUsage.toTrackedBaseAndAccessPathSimple import io.joern.dataflowengineoss.semanticsloader.Semantics +import io.joern.dataflowengineoss.{globalFromLiteral, identifierToFirstUsages} import io.shiftleft.codepropertygraph.generated.nodes.* import io.shiftleft.codepropertygraph.generated.{EdgeTypes, Operators, PropertyNames} import io.shiftleft.semanticcpg.accesspath.MatchResult import io.shiftleft.semanticcpg.language.* +import org.slf4j.LoggerFactory import overflowdb.BatchedUpdate.DiffGraphBuilder import scala.collection.{Set, mutable} @@ -14,7 +15,7 @@ import scala.collection.{Set, mutable} /** Creation of data dependence edges based on solution of the ReachingDefProblem. */ class DdgGenerator(semantics: Semantics) { - + private val logger = LoggerFactory.getLogger(getClass) implicit val s: Semantics = semantics /** Once reaching definitions have been computed, we create a data dependence graph by checking which reaching @@ -168,6 +169,7 @@ class DdgGenerator(semantics: Semantics) { } def addEdgesToCapturedIdentifiersAndParameters(): Unit = { + val identifierDestPairs = method._identifierViaContainsOut .flatMap { identifier => @@ -202,18 +204,22 @@ class DdgGenerator(semantics: Semantics) { } } } + try { + addEdgesFromEntryNode() + allNodes.foreach { + case call: Call => addEdgesToCallSite(call) + case ret: Return => addEdgesToReturn(ret) + case paramOut: MethodParameterOut => addEdgesToMethodParameterOut(paramOut) + case _ => + } - addEdgesFromEntryNode() - allNodes.foreach { - case call: Call => addEdgesToCallSite(call) - case ret: Return => addEdgesToReturn(ret) - case paramOut: MethodParameterOut => addEdgesToMethodParameterOut(paramOut) - case _ => + addEdgesToCapturedIdentifiersAndParameters() + addEdgesToExitNode(method.methodReturn) + addEdgesFromLoneIdentifiersToExit(method) + } catch { + case exception: Exception => + logger.warn("Error in DdgGenerator,", exception) } - - addEdgesToCapturedIdentifiersAndParameters() - addEdgesToExitNode(method.methodReturn) - addEdgesFromLoneIdentifiersToExit(method) } private def addEdge(fromNode: StoredNode, toNode: StoredNode, variable: String = "")(implicit diff --git a/dataflowengineoss/src/main/scala/io/joern/dataflowengineoss/slicing/UsageSlicing.scala b/dataflowengineoss/src/main/scala/io/joern/dataflowengineoss/slicing/UsageSlicing.scala index 41896509c2c5..3e58f9cfd8a1 100644 --- a/dataflowengineoss/src/main/scala/io/joern/dataflowengineoss/slicing/UsageSlicing.scala +++ b/dataflowengineoss/src/main/scala/io/joern/dataflowengineoss/slicing/UsageSlicing.scala @@ -344,15 +344,22 @@ object UsageSlicing { typeDecl.fullName, typeDecl.member.map(m => DefComponent.fromNode(m)).collectAll[LocalDef].l, typeDecl.method - .map(m => - ObservedCall( - m.name, - Option(m.fullName), - m.parameter.map(_.typeFullName).toList, - m.methodReturn.typeFullName, - m.lineNumber.map(_.intValue()), - m.columnNumber.map(_.intValue()) - ) + .flatMap(m => + Try( + ObservedCall( + m.name, + Option(m.fullName), + m.parameter.map(_.typeFullName).toList, + m.methodReturn.typeFullName, + m.lineNumber.map(_.intValue()), + m.columnNumber.map(_.intValue()) + ) + ) match { + case Success(value) => Some(value) + case Failure(exception) => + logger.warn("Error in dataflow UsageSlicing", exception) + None + } ) .l, typeDecl.filename, diff --git a/joern-cli/frontends/x2cpg/src/main/scala/io/joern/x2cpg/passes/frontend/XTypeRecovery.scala b/joern-cli/frontends/x2cpg/src/main/scala/io/joern/x2cpg/passes/frontend/XTypeRecovery.scala index 234f018b8d18..2424d706553f 100644 --- a/joern-cli/frontends/x2cpg/src/main/scala/io/joern/x2cpg/passes/frontend/XTypeRecovery.scala +++ b/joern-cli/frontends/x2cpg/src/main/scala/io/joern/x2cpg/passes/frontend/XTypeRecovery.scala @@ -344,20 +344,25 @@ abstract class RecoverForXCompilationUnit[CompilationUnitType <: AstNode]( } override def run(): Unit = { - // Set known aliases that point to imports for local and external methods/modules - importNodes.foreach(visitImport) - // Look at symbols with existing type info - prepopulateSymbolTable() - // Prune import names if the methods exist in the CPG - postVisitImports() - // Populate local symbol table with assignments - assignments.foreach(visitAssignments) - // See if any new information are in the parameters of methods - returns.foreach(visitReturns) - // Persist findings - setTypeInformation() - // Entrypoint for any final changes - postSetTypeInformation() + try { + // Set known aliases that point to imports for local and external methods/modules + importNodes.foreach(visitImport) + // Look at symbols with existing type info + prepopulateSymbolTable() + // Prune import names if the methods exist in the CPG + postVisitImports() + // Populate local symbol table with assignments + assignments.foreach(visitAssignments) + // See if any new information are in the parameters of methods + returns.foreach(visitReturns) + // Persist findings + setTypeInformation() + // Entrypoint for any final changes + postSetTypeInformation() + } catch { + case ex: Exception => + logger.warn(s"Error in XTypeRecovery ", ex) + } } private def debugLocation(n: AstNode): String = { @@ -643,7 +648,14 @@ abstract class RecoverForXCompilationUnit[CompilationUnitType <: AstNode]( protected def methodReturnValues(methodFullNames: Seq[String]): Set[String] = { val rs = cpg.method .fullNameExact(methodFullNames*) - .methodReturn + .flatMap(method => { + Try(method.methodReturn) match { + case Success(value) => Some(value) + case Failure(exception) => + logger.warn(s"Error in Type Recovery for method ${method.fullName} from file ${method.filename}") + None + } + }) .flatMap(mr => mr.typeFullName +: (mr.dynamicTypeHintFullName ++ mr.possibleTypes)) .filterNot(_.equals("ANY")) .toSet