Skip to content

Commit e55c718

Browse files
authored
Merge pull request #126 from microsoft/powershell-global-parameter-positions
PS: Include parameter positions for top level functions
2 parents c93daeb + 6bb859d commit e55c718

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

powershell/ql/lib/semmle/code/powershell/dataflow/internal/DataFlowDispatch.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@ private module Cached {
241241
call = ns.getABindingCall() and
242242
exists(call.getArgument(pos))
243243
)
244+
or
245+
// Uncalled functions are never the target of a call returned by
246+
// `ns.getABindingCall()`, but those parameters should still have
247+
// positions since SSA depends on this.
248+
// In particular, global scope is also an uncalled function.
249+
any(Parameter p).getIndexExcludingPipelines() = pos and
250+
ns.isEmpty()
244251
} or
245252
TPipelineParameter()
246253
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
param([string]$Source)
1+
param([string]$Source1, [string]$Source2, [string]$Source3, [string]$Source4)
22

3-
Sink $Source # $ hasValueFlow
3+
Sink $Source1 # $ hasValueFlow=1
4+
Sink $Source2 # $ hasValueFlow=2
5+
Sink $Source3 # $ hasValueFlow=3
6+
Sink $Source4 # $ hasValueFlow=4

powershell/ql/test/library-tests/dataflow/params/test.expected

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
models
22
edges
3-
| global.ps1:1:7:1:22 | Source | global.ps1:3:6:3:13 | Source | provenance | |
3+
| global.ps1:1:7:1:23 | Source1 | global.ps1:3:6:3:14 | Source1 | provenance | |
4+
| global.ps1:1:25:1:41 | Source2 | global.ps1:4:6:4:14 | Source2 | provenance | |
5+
| global.ps1:1:43:1:59 | Source3 | global.ps1:5:6:5:14 | Source3 | provenance | |
6+
| global.ps1:1:61:1:77 | Source4 | global.ps1:6:6:6:14 | Source4 | provenance | |
47
| test.ps1:1:14:1:16 | a | test.ps1:2:10:2:12 | a | provenance | |
58
| test.ps1:5:6:5:16 | Source | test.ps1:6:5:6:7 | x | provenance | |
69
| test.ps1:6:5:6:7 | x | test.ps1:1:14:1:16 | a | provenance | |
@@ -140,8 +143,14 @@ edges
140143
| test.ps1:39:24:39:31 | second | test.ps1:8:24:8:26 | y | provenance | |
141144
| test.ps1:39:32:39:38 | first | test.ps1:8:20:8:22 | x | provenance | |
142145
nodes
143-
| global.ps1:1:7:1:22 | Source | semmle.label | Source |
144-
| global.ps1:3:6:3:13 | Source | semmle.label | Source |
146+
| global.ps1:1:7:1:23 | Source1 | semmle.label | Source1 |
147+
| global.ps1:1:25:1:41 | Source2 | semmle.label | Source2 |
148+
| global.ps1:1:43:1:59 | Source3 | semmle.label | Source3 |
149+
| global.ps1:1:61:1:77 | Source4 | semmle.label | Source4 |
150+
| global.ps1:3:6:3:14 | Source1 | semmle.label | Source1 |
151+
| global.ps1:4:6:4:14 | Source2 | semmle.label | Source2 |
152+
| global.ps1:5:6:5:14 | Source3 | semmle.label | Source3 |
153+
| global.ps1:6:6:6:14 | Source4 | semmle.label | Source4 |
145154
| test.ps1:1:14:1:16 | a | semmle.label | a |
146155
| test.ps1:2:10:2:12 | a | semmle.label | a |
147156
| test.ps1:5:6:5:16 | Source | semmle.label | Source |
@@ -224,7 +233,10 @@ nodes
224233
subpaths
225234
testFailures
226235
#select
227-
| global.ps1:3:6:3:13 | Source | global.ps1:1:7:1:22 | Source | global.ps1:3:6:3:13 | Source | $@ | global.ps1:1:7:1:22 | Source | Source |
236+
| global.ps1:3:6:3:14 | Source1 | global.ps1:1:7:1:23 | Source1 | global.ps1:3:6:3:14 | Source1 | $@ | global.ps1:1:7:1:23 | Source1 | Source1 |
237+
| global.ps1:4:6:4:14 | Source2 | global.ps1:1:25:1:41 | Source2 | global.ps1:4:6:4:14 | Source2 | $@ | global.ps1:1:25:1:41 | Source2 | Source2 |
238+
| global.ps1:5:6:5:14 | Source3 | global.ps1:1:43:1:59 | Source3 | global.ps1:5:6:5:14 | Source3 | $@ | global.ps1:1:43:1:59 | Source3 | Source3 |
239+
| global.ps1:6:6:6:14 | Source4 | global.ps1:1:61:1:77 | Source4 | global.ps1:6:6:6:14 | Source4 | $@ | global.ps1:1:61:1:77 | Source4 | Source4 |
228240
| test.ps1:2:10:2:12 | a | test.ps1:5:6:5:16 | Source | test.ps1:2:10:2:12 | a | $@ | test.ps1:5:6:5:16 | Source | Source |
229241
| test.ps1:9:10:9:12 | x | test.ps1:14:10:14:20 | Source | test.ps1:9:10:9:12 | x | $@ | test.ps1:14:10:14:20 | Source | Source |
230242
| test.ps1:10:10:10:12 | y | test.ps1:15:11:15:21 | Source | test.ps1:10:10:10:12 | y | $@ | test.ps1:15:11:15:21 | Source | Source |

0 commit comments

Comments
 (0)