Skip to content

Commit

Permalink
[dataflowengineoss] refine return value semantics honouring (#4680)
Browse files Browse the repository at this point in the history
* [dataflowengineoss] refine return value semantics honoring

* fix c2cpg test

* make sure parentNode is an argument of childNode
  • Loading branch information
xavierpinho committed Jun 19, 2024
1 parent 44d5fc7 commit 195f015
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ object EdgeValidator {
case (childNode: Expression, parentNode)
if isCallRetval(parentNode) || !isValidEdgeToExpression(parentNode, childNode) =>
false
case (childNode: Call, parentNode: Expression)
if isCallRetval(childNode) && childNode.argument.contains(parentNode) =>
// e.g. foo(x), but there are semantics for `foo` that don't taint its return value
// in which case we don't want `x` to taint `foo(x)`.
false
case (childNode: Expression, parentNode: Expression)
if parentNode.isArgToSameCallWith(childNode) && childNode.isDefined && parentNode.isUsed =>
parentNode.hasDefinedFlowTo(childNode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DataFlowTests extends DataFlowCodeToCpgSuite {

"find flows to `free`" in {
val source = cpg.identifier
val sink = cpg.call.name("free")
val sink = cpg.call.name("free").argument(1)
sink.reachableByFlows(source).l.map(flowToResultPairs).distinct.size shouldBe 6
}

Expand Down Expand Up @@ -1311,7 +1311,7 @@ class DataFlowTests extends DataFlowCodeToCpgSuite {

"find flows to `free`" in {
val source = cpg.identifier
val sink = cpg.call.name("free")
val sink = cpg.call.name("free").argument(1)
sink.reachableByFlows(source).l.map(flowToResultPairs).distinct.toSet.size shouldBe 6
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class DataFlowTests extends PySrc2CpgFixture(withOssDataflow = true) {
flows shouldBe empty
}

"no flow from aliased literal to imported external method call return value given argument1-only semantics" ignore {
"no flow from aliased literal to imported external method call return value given argument1-only semantics" in {
val cpg = code("""
|from helpers import foo
|a = 20
Expand All @@ -96,7 +96,7 @@ class DataFlowTests extends PySrc2CpgFixture(withOssDataflow = true) {
flows shouldBe empty
}

"no flow from literal to imported external method return value given empty semantics" ignore {
"no flow from literal to imported external method return value given empty semantics" in {
val cpg = code("""
|from helpers import foo
|print(foo(20))
Expand All @@ -108,7 +108,7 @@ class DataFlowTests extends PySrc2CpgFixture(withOssDataflow = true) {
flows shouldBe empty
}

"no flow from literal to imported external method return value given receiver-only semantics" ignore {
"no flow from literal to imported external method return value given receiver-only semantics" in {
val cpg = code("""
|from helpers import foo
|print(foo(20))
Expand All @@ -120,7 +120,7 @@ class DataFlowTests extends PySrc2CpgFixture(withOssDataflow = true) {
flows shouldBe empty
}

"no flow from literal to imported external method return value given argument1-only semantics" ignore {
"no flow from literal to imported external method return value given argument1-only semantics" in {
val cpg = code("""
|from helpers import foo
|print(foo(20))
Expand Down

0 comments on commit 195f015

Please sign in to comment.