Skip to content

Commit

Permalink
fix dataflow of return statement (#2244)
Browse files Browse the repository at this point in the history
  • Loading branch information
Liyw979 authored Feb 5, 2023
1 parent 7122dfd commit 93ba087
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class DdgGenerator(semantics: Semantics) {
.filterNot(x => numberToNode.get(x).contains(use))
.flatMap(numberToNode.get)
.foreach { inElemNode =>
addEdge(inElemNode, ret, nodeToEdgeLabel(inElemNode))
addEdge(inElemNode, use, nodeToEdgeLabel(inElemNode))
}
if (inElements.isEmpty) {
addEdge(method, ret)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.joern.javasrc2cpg.querying.dataflow

import io.joern.javasrc2cpg.testfixtures.JavaDataflowFixture
import io.joern.dataflowengineoss.language._
import io.shiftleft.semanticcpg.language._

class ReturnTests extends JavaDataflowFixture {

behavior of "Dataflow to return statements"

override val code: String =
"""
|public class Foo {
| public void bar() {
| int x = 42;
| return x;
| }
|}
|""".stripMargin

it should "find a flow from x in return statement to 42" in {
val src = cpg.literal("42")
val snk = cpg.identifier("x").lineNumber(5)
snk.reachableBy(src).size shouldBe 1
}
}

0 comments on commit 93ba087

Please sign in to comment.