From 494ef7a44cbd8e8871f9252b5aca99e7a2fd9955 Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Fri, 4 Oct 2024 20:08:20 +0100 Subject: [PATCH] PS: Fix missing flow. --- .../dataflow/internal/DataFlowPrivate.qll | 6 ++++++ .../library-tests/dataflow/fields/test.expected | 15 +++++++++++++++ .../test/library-tests/dataflow/fields/test.ps1 | 4 ++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/powershell/ql/lib/semmle/code/powershell/dataflow/internal/DataFlowPrivate.qll b/powershell/ql/lib/semmle/code/powershell/dataflow/internal/DataFlowPrivate.qll index 05b1cb7d50b..a39c42b2139 100644 --- a/powershell/ql/lib/semmle/code/powershell/dataflow/internal/DataFlowPrivate.qll +++ b/powershell/ql/lib/semmle/code/powershell/dataflow/internal/DataFlowPrivate.qll @@ -528,6 +528,12 @@ predicate storeStep(Node node1, ContentSet c, Node node2) { or not exists(e.getValue().asInt()) ) + or + exists(Content::KnownElementContent ec, int index | + node2.asExpr().(CfgNodes::ExprNodes::ArrayLiteralCfgNode).getElement(index) = node1.asExpr() and + c.isKnownOrUnknownElement(ec) and + index = ec.getIndex().asInt() + ) } /** diff --git a/powershell/ql/test/library-tests/dataflow/fields/test.expected b/powershell/ql/test/library-tests/dataflow/fields/test.expected index c28d812c778..50635fd5358 100644 --- a/powershell/ql/test/library-tests/dataflow/fields/test.expected +++ b/powershell/ql/test/library-tests/dataflow/fields/test.expected @@ -157,6 +157,12 @@ edges | test.ps1:31:6:31:22 | ...[...] [element 2] | test.ps1:31:6:31:33 | ...[...] | provenance | | | test.ps1:31:6:31:22 | ...[...] [element 3] | test.ps1:31:6:31:33 | ...[...] | provenance | | | test.ps1:31:6:31:22 | ...[...] [element 4] | test.ps1:31:6:31:33 | ...[...] | provenance | | +| test.ps1:33:6:33:17 | Source | test.ps1:35:15:35:17 | x | provenance | | +| test.ps1:35:9:35:17 | ...,... [element 2] | test.ps1:38:6:38:11 | arr8 [element 2] | provenance | | +| test.ps1:35:9:35:17 | ...,... [element 2] | test.ps1:39:6:39:11 | arr8 [element 2] | provenance | | +| test.ps1:35:15:35:17 | x | test.ps1:35:9:35:17 | ...,... [element 2] | provenance | | +| test.ps1:38:6:38:11 | arr8 [element 2] | test.ps1:38:6:38:14 | ...[...] | provenance | | +| test.ps1:39:6:39:11 | arr8 [element 2] | test.ps1:39:6:39:21 | ...[...] | provenance | | nodes | test.ps1:1:1:1:3 | [post] a [f] | semmle.label | [post] a [f] | | test.ps1:1:8:1:18 | Source | semmle.label | Source | @@ -287,6 +293,13 @@ nodes | test.ps1:31:6:31:22 | ...[...] [element 3] | semmle.label | ...[...] [element 3] | | test.ps1:31:6:31:22 | ...[...] [element 4] | semmle.label | ...[...] [element 4] | | test.ps1:31:6:31:33 | ...[...] | semmle.label | ...[...] | +| test.ps1:33:6:33:17 | Source | semmle.label | Source | +| test.ps1:35:9:35:17 | ...,... [element 2] | semmle.label | ...,... [element 2] | +| test.ps1:35:15:35:17 | x | semmle.label | x | +| test.ps1:38:6:38:11 | arr8 [element 2] | semmle.label | arr8 [element 2] | +| test.ps1:38:6:38:14 | ...[...] | semmle.label | ...[...] | +| test.ps1:39:6:39:11 | arr8 [element 2] | semmle.label | arr8 [element 2] | +| test.ps1:39:6:39:21 | ...[...] | semmle.label | ...[...] | subpaths testFailures #select @@ -299,3 +312,5 @@ testFailures | test.ps1:26:6:26:25 | ...[...] | test.ps1:25:23:25:33 | Source | test.ps1:26:6:26:25 | ...[...] | $@ | test.ps1:25:23:25:33 | Source | Source | | test.ps1:30:6:30:17 | ...[...] | test.ps1:29:31:29:41 | Source | test.ps1:30:6:30:17 | ...[...] | $@ | test.ps1:29:31:29:41 | Source | Source | | test.ps1:31:6:31:33 | ...[...] | test.ps1:29:31:29:41 | Source | test.ps1:31:6:31:33 | ...[...] | $@ | test.ps1:29:31:29:41 | Source | Source | +| test.ps1:38:6:38:14 | ...[...] | test.ps1:33:6:33:17 | Source | test.ps1:38:6:38:14 | ...[...] | $@ | test.ps1:33:6:33:17 | Source | Source | +| test.ps1:39:6:39:21 | ...[...] | test.ps1:33:6:33:17 | Source | test.ps1:39:6:39:21 | ...[...] | $@ | test.ps1:33:6:33:17 | Source | Source | diff --git a/powershell/ql/test/library-tests/dataflow/fields/test.ps1 b/powershell/ql/test/library-tests/dataflow/fields/test.ps1 index 6b480820c5b..f235c96e948 100644 --- a/powershell/ql/test/library-tests/dataflow/fields/test.ps1 +++ b/powershell/ql/test/library-tests/dataflow/fields/test.ps1 @@ -35,8 +35,8 @@ $x = Source "10" $arr8 = 0, 1, $x Sink $arr8[0] # clean Sink $arr8[1] # clean -Sink $arr8[2] # $ MISSING: hasValueFlow=10 -Sink $arr8[$unknown] # MISSING: hasValueFlow=10 +Sink $arr8[2] # $ hasValueFlow=10 +Sink $arr8[$unknown] # $ hasValueFlow=10 $y = Source "11"