Skip to content

Commit

Permalink
Flow From Identifier Receiver Source (#2828)
Browse files Browse the repository at this point in the history
Extended the fix #2722 by testing when the source is an identifier and accommodating this case
  • Loading branch information
DavidBakerEffendi committed Jun 7, 2023
1 parent 30ef1b8 commit c81a77d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ class SourceToStartingPoints(src: StoredNode) extends RecursiveTask[List[CfgNode
case x: Declaration =>
List(x).collectAll[CfgNode].toList
case x: Identifier =>
withFieldAndIndexAccesses(
(withFieldAndIndexAccesses(
List(x).collectAll[CfgNode].toList ++ x.refsTo.collectAll[Local].flatMap(sourceToStartingPoints)
) ++ x.refsTo.capturedByMethodRef.referencedMethod.flatMap(m => usagesForName(x.name, m))
) ++ x.refsTo.capturedByMethodRef.referencedMethod.flatMap(m => usagesForName(x.name, m))).flatMap {
case x: Call => sourceToStartingPoints(x)
case x => List(x)
}
case x: Call =>
(x._receiverIn.l :+ x).collect { case y: CfgNode => y }
case x => List(x).collect { case y: CfgNode => y }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,18 @@ class RegexDefinedFlowsDataFlowTests
}
}

"flows from receivers directly" should {
val cpg = code("""
|class Foo:
| def func():
| return "x"
|print(Foo.func())
|""".stripMargin)
"be found" in {
val src = cpg.identifier("Foo").l
val snk = cpg.call("print").l
snk.reachableByFlows(src).size shouldBe 2
}
}

}

0 comments on commit c81a77d

Please sign in to comment.