Skip to content

Commit

Permalink
Backport fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Prabhu Subramanian <[email protected]>
  • Loading branch information
prabhu committed Nov 16, 2024
1 parent bb51a3d commit 34c82e0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ object Path:
val method = cfgNode.method
sinkCode = method.fullName
caption = if srcNode.code != "this" then s"Source: ${srcNode.code}" else ""
if srcTags.nonEmpty then caption += s"\nSource Tags: ${srcTags}"
caption += s"\nSink: ${sinkCode}\n"
if sinkTags.nonEmpty then caption += s"Sink Tags: ${sinkTags}\n"
var hasCheckLike: Boolean = false;
if srcTags.nonEmpty then caption += s"\nSource Tags: $srcTags"
caption += s"\nSink: $sinkCode\n"
if sinkTags.nonEmpty then caption += s"Sink Tags: $sinkTags\n"
var hasCheckLike: Boolean = false
val tableRows = ArrayBuffer[Array[String]]()
val addedPaths = Set[String]()
path.elements.foreach { astNode =>
val nodeType = astNode.getClass.getSimpleName
val lineNumber = astNode.lineNumber.getOrElse("").toString
val fileName = astNode.file.name.headOption.getOrElse("").replace("<unknown>", "")
var fileLocation = s"${fileName}#${lineNumber}"
var fileLocation = s"$fileName#$lineNumber"
var tags: String = tagAsString(astNode.tag)
if fileLocation == "#" then fileLocation = "N/A"
astNode match
Expand Down Expand Up @@ -96,7 +96,7 @@ object Path:
then
tags = tagAsString(identifier.inCall.head.tag)
if !addedPaths.contains(
s"${fileName}#${lineNumber}"
s"$fileName#$lineNumber"
) && identifier.inCall.nonEmpty
then
tableRows += Array[String](
Expand Down Expand Up @@ -185,13 +185,13 @@ object Path:
)
end match
if isCheckLike(tags) then hasCheckLike = true
addedPaths += s"${fileName}#${lineNumber}"
addedPaths += s"$fileName#$lineNumber"
}
try
if hasCheckLike then caption = s"This flow has mitigations in place.\n$caption"
printFlows(tableRows, caption)
catch
case exc: Exception =>
case _: Exception =>
caption

private def addEmphasis(str: String, isCheckLike: Boolean): String =
Expand All @@ -217,7 +217,7 @@ object Path:
val trow: Array[String] = row.tail
if !trow(3).startsWith("<operator") && trow(3) != "<empty>" && trow(3) != "RET" then
val tagsStr: String = if trow(4).nonEmpty then s"Tags: ${trow(4)}" else ""
val methodStr = s"${trow(1)}\n${tagsStr}"
val methodStr = s"${trow(1)}\n$tagsStr"
table.add_row(
simplifyFilePath(trow(0)),
methodStr.stripMargin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ class SourceToStartingPoints(src: StoredNode) extends RecursiveTask[List[CfgNode

val usagesInOtherClasses = cpg.method.flatMap { m =>
m.fieldAccess
.where(_.argument(1).isIdentifier.typeFullNameExact(typeDecl.fullName))
.or(
_.argument(1).isIdentifier.typeFullNameExact(typeDecl.fullName),
_.argument(1).isTypeRef.typeFullNameExact(typeDecl.fullName)
)
.where { x =>
astNode match
case identifier: Identifier =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class TypeDeclTraversal(val traversal: Iterator[TypeDecl]) extends AnyVal:
/** Direct and transitive base type declaration.
*/
def derivedTypeDeclTransitive: Iterator[TypeDecl] =
traversal.repeat(_.derivedTypeDecl)(_.emitAllButFirst)
traversal.repeat(_.derivedTypeDecl)(_.emitAllButFirst.dedup)

/** Direct base type declaration.
*/
Expand All @@ -67,7 +67,7 @@ class TypeDeclTraversal(val traversal: Iterator[TypeDecl]) extends AnyVal:
/** Direct and transitive base type declaration.
*/
def baseTypeDeclTransitive: Iterator[TypeDecl] =
traversal.repeat(_.baseTypeDecl)(_.emitAllButFirst)
traversal.repeat(_.baseTypeDecl)(_.emitAllButFirst.dedup)

/** Traverse to alias type declarations.
*/
Expand Down Expand Up @@ -106,7 +106,7 @@ class TypeDeclTraversal(val traversal: Iterator[TypeDecl]) extends AnyVal:
/** Direct and transitive alias type declarations.
*/
def aliasTypeDeclTransitive: Iterator[TypeDecl] =
traversal.repeat(_.aliasTypeDecl)(_.emitAllButFirst)
traversal.repeat(_.aliasTypeDecl)(_.emitAllButFirst.dedup)
end TypeDeclTraversal

object TypeDeclTraversal:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class TypeTraversal(val traversal: Iterator[Type]) extends AnyVal:
/** Direct and transitive base types of the corresponding type declaration.
*/
def baseTypeTransitive: Iterator[Type] =
traversal.repeat(_.baseType)(_.emitAllButFirst)
traversal.repeat(_.baseType)(_.emitAllButFirst.dedup)

/** Direct derived types.
*/
Expand All @@ -54,7 +54,7 @@ class TypeTraversal(val traversal: Iterator[Type]) extends AnyVal:
/** Direct and transitive derived types.
*/
def derivedTypeTransitive: Iterator[Type] =
traversal.repeat(_.derivedType)(_.emitAllButFirst)
traversal.repeat(_.derivedType)(_.emitAllButFirst.dedup)

/** Type declarations which derive from this type.
*/
Expand All @@ -69,7 +69,7 @@ class TypeTraversal(val traversal: Iterator[Type]) extends AnyVal:
/** Direct and transitive alias types.
*/
def aliasTypeTransitive: Iterator[Type] =
traversal.repeat(_.aliasType)(_.emitAllButFirst)
traversal.repeat(_.aliasType)(_.emitAllButFirst.dedup)

def localOfType: Iterator[Local] =
traversal.flatMap(_._localViaEvalTypeIn)
Expand Down

0 comments on commit 34c82e0

Please sign in to comment.