Skip to content

Commit 1637df0

Browse files
authored
Merge pull request #199 from microsoft/fix-top-level-arguments
PS: Fix a couple of missing local flow sources
2 parents 5abde74 + 4aa9f85 commit 1637df0

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

powershell/ql/lib/semmle/code/powershell/ast/internal/FunctionBase.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ class FunctionBase extends Ast, TFunctionBase {
2121

2222
final int getNumberOfParameters() { result = count(this.getAParameter()) }
2323
}
24+
25+
/**
26+
* The implicit function that represents the entire script block in a file.
27+
*/
28+
class TopLevelFunction extends FunctionBase, TTopLevelFunction { }

powershell/ql/lib/semmle/code/powershell/ast/internal/Synthesis.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,11 @@ private module LiteralSynth {
675675
s = "null" and
676676
child = SynthChild(NullLiteralKind())
677677
or
678-
Raw::isEnvVariableAccess(va, s) and
679-
child = SynthChild(EnvVariableKind(s))
678+
exists(string s0 |
679+
s = "env:" + s0 and
680+
Raw::isEnvVariableAccess(va, s0) and
681+
child = SynthChild(EnvVariableKind(s0))
682+
)
680683
or
681684
isAutomaticVariableAccess(va, s) and
682685
child = SynthChild(AutomaticVariableKind(s))

powershell/ql/lib/semmle/code/powershell/dataflow/flowsources/Local.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private class ExternalCommandLineArgumentSource extends CommandLineArgumentSourc
5959
* A data flow source that represents the parameters of the `Main` method of a program.
6060
*/
6161
private class MainMethodArgumentSource extends CommandLineArgumentSource {
62-
MainMethodArgumentSource() { this.asParameter().getParent() instanceof TopLevelScriptBlock }
62+
MainMethodArgumentSource() { this.asParameter().getFunction() instanceof TopLevelFunction }
6363
}
6464

6565
/**

powershell/ql/lib/semmle/code/powershell/frameworks/SystemConsole/model.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
edges
2+
| test.ps1:1:8:1:9 | x | test.ps1:3:28:3:47 | Get-Process -Id $x | provenance | |
3+
| test.ps1:5:10:5:20 | my_var | test.ps1:7:3:7:19 | $code --enabled | provenance | |
24
nodes
5+
| test.ps1:1:8:1:9 | x | semmle.label | x |
6+
| test.ps1:3:28:3:47 | Get-Process -Id $x | semmle.label | Get-Process -Id $x |
7+
| test.ps1:5:10:5:20 | my_var | semmle.label | my_var |
8+
| test.ps1:7:3:7:19 | $code --enabled | semmle.label | $code --enabled |
39
subpaths
410
#select
11+
| test.ps1:3:28:3:47 | Get-Process -Id $x | test.ps1:1:8:1:9 | x | test.ps1:3:28:3:47 | Get-Process -Id $x | This command depends on a $@. | test.ps1:1:8:1:9 | x | user-provided value |
12+
| test.ps1:7:3:7:19 | $code --enabled | test.ps1:5:10:5:20 | my_var | test.ps1:7:3:7:19 | $code --enabled | This command depends on a $@. | test.ps1:5:10:5:20 | my_var | user-provided value |

0 commit comments

Comments
 (0)