Skip to content

Commit 398d27b

Browse files
committed
PS: Fix missing AST child.
1 parent 28de6ed commit 398d27b

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

powershell/ql/lib/semmle/code/powershell/ast/internal/Raw/ChildIndex.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ newtype ChildIndex =
1414
CatchClauseBody() or
1515
CatchClauseType(int i) { exists(any(CatchClause c).getCatchType(i)) } or
1616
CmdElement_(int i) { exists(any(Cmd cmd).getElement(i)) } or // TODO: Get rid of this?
17+
CmdParameterExpr() or
1718
CmdCallee() or
1819
CmdRedirection(int i) { exists(any(Cmd cmd).getRedirection(i)) } or
1920
CmdExprExpr() or
@@ -127,6 +128,8 @@ string stringOfChildIndex(ChildIndex i) {
127128
or
128129
i = CmdElement_(_) and result = "CmdElement"
129130
or
131+
i = CmdParameterExpr() and result = "CmdParameterExpr"
132+
or
130133
i = CmdCallee() and result = "CmdCallee"
131134
or
132135
i = CmdRedirection(_) and result = "CmdRedirection"

powershell/ql/lib/semmle/code/powershell/ast/internal/Raw/CommandParameter.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ class CmdParameter extends @command_parameter, CmdElement {
55

66
string getName() { command_parameter(this, result) }
77

8-
Ast getExpr() {
9-
command_parameter_argument(this, result)
8+
Ast getExpr() { command_parameter_argument(this, result) }
9+
10+
final override Ast getChild(ChildIndex i) {
11+
i instanceof CmdParameterExpr and
12+
result = this.getExpr()
1013
}
1114

1215
Cmd getCmd() { result.getElement(_) = this }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
| test.ps1:1:1:1:33 | Call to set-executionpolicy | Insecure use of 'Set-ExecutionPolicy'. |
22
| test.ps1:5:1:5:54 | Call to set-executionpolicy | Insecure use of 'Set-ExecutionPolicy'. |
3+
| test.ps1:7:1:7:39 | Call to set-executionpolicy | Insecure use of 'Set-ExecutionPolicy'. |

powershell/ql/test/query-tests/security/cwe-250/test.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Set-ExecutionPolicy Bypass -Scope Process -Force # GOOD
44
Set-ExecutionPolicy RemoteSigned -Scope Process -Force # GOOD
55
Set-ExecutionPolicy Bypass -Scope MachinePolicy -Force # BAD
66

7-
Set-ExecutionPolicy Bypass -Force:$true # BAD [NOT DETECTED]
7+
Set-ExecutionPolicy Bypass -Force:$true # BAD
88
Set-ExecutionPolicy Bypass -Force:$false # GOOD
99

1010
Set-ExecutionPolicy Bypass # GOOD

0 commit comments

Comments
 (0)