Skip to content

Commit 5f07641

Browse files
committed
PS: Fix false positive by fixing the 'getCommand' predicates in 'CallOperatorCfgNode' and 'CallOperator'. Also fix 'DotSourcingOperator::getPath' while here.
1 parent 75d37dc commit 5f07641

File tree

4 files changed

+4
-8
lines changed

4 files changed

+4
-8
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ class CmdCall extends CallExpr, TCmd {
7676
class CallOperator extends CmdCall {
7777
CallOperator() { getRawAst(this) instanceof Raw::CallOperator }
7878

79-
Expr getCommand() { result = this.getArgument(0) }
79+
Expr getCommand() { result = this.getCallee() }
8080
}
8181

8282
/** A call to the dot-sourcing `.`. */
8383
class DotSourcingOperator extends CmdCall {
8484
DotSourcingOperator() { getRawAst(this) instanceof Raw::DotSourcingOperator }
8585

86-
Expr getPath() { result = this.getArgument(0) }
86+
Expr getPath() { result = this.getCallee() }
8787
}
8888

8989
class JoinPath extends CmdCall {

powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ module ExprNodes {
605605

606606
override CallOperator getExpr() { result = e }
607607

608-
ExprCfgNode getCommand() { result = this.getArgument(0) }
608+
ExprCfgNode getCommand() { result = this.getCallee() }
609609
}
610610

611611
private class ToStringCallChildmapping extends CallExprChildMapping instanceof ToStringCall {

powershell/ql/test/query-tests/security/cwe-078/CommandInjection/CommandInjection.expected

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ edges
5353
| test.ps1:170:36:170:41 | input | test.ps1:129:11:129:20 | userinput | provenance | |
5454
| test.ps1:172:42:172:47 | input | test.ps1:136:11:136:20 | userinput | provenance | |
5555
| test.ps1:173:42:173:47 | input | test.ps1:144:11:144:20 | userinput | provenance | |
56-
| test.ps1:214:10:214:32 | Call to read-host | test.ps1:215:16:215:19 | $o | provenance | Src:MaD:0 |
5756
nodes
5857
| test.ps1:3:11:3:20 | userinput | semmle.label | userinput |
5958
| test.ps1:4:23:4:52 | Get-Process -Name $UserInput | semmle.label | Get-Process -Name $UserInput |
@@ -110,8 +109,6 @@ nodes
110109
| test.ps1:170:36:170:41 | input | semmle.label | input |
111110
| test.ps1:172:42:172:47 | input | semmle.label | input |
112111
| test.ps1:173:42:173:47 | input | semmle.label | input |
113-
| test.ps1:214:10:214:32 | Call to read-host | semmle.label | Call to read-host |
114-
| test.ps1:215:16:215:19 | $o | semmle.label | $o |
115112
subpaths
116113
#select
117114
| test.ps1:4:23:4:52 | Get-Process -Name $UserInput | test.ps1:152:10:152:32 | Call to read-host | test.ps1:4:23:4:52 | Get-Process -Name $UserInput | This command depends on a $@. | test.ps1:152:10:152:32 | Call to read-host | user-provided value |
@@ -132,4 +129,3 @@ subpaths
132129
| test.ps1:131:28:131:37 | UserInput | test.ps1:152:10:152:32 | Call to read-host | test.ps1:131:28:131:37 | UserInput | This command depends on a $@. | test.ps1:152:10:152:32 | Call to read-host | user-provided value |
133130
| test.ps1:139:50:139:59 | UserInput | test.ps1:152:10:152:32 | Call to read-host | test.ps1:139:50:139:59 | UserInput | This command depends on a $@. | test.ps1:152:10:152:32 | Call to read-host | user-provided value |
134131
| test.ps1:147:63:147:72 | UserInput | test.ps1:152:10:152:32 | Call to read-host | test.ps1:147:63:147:72 | UserInput | This command depends on a $@. | test.ps1:152:10:152:32 | Call to read-host | user-provided value |
135-
| test.ps1:215:16:215:19 | $o | test.ps1:214:10:214:32 | Call to read-host | test.ps1:215:16:215:19 | $o | This command depends on a $@. | test.ps1:214:10:214:32 | Call to read-host | user-provided value |

powershell/ql/test/query-tests/security/cwe-078/CommandInjection/test.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,5 +212,5 @@ Invoke-InvokeExpressionInjectionSafe4 -UserInput $input
212212
function false-positive-in-call-operator($d)
213213
{
214214
$o = Read-Host "enter input"
215-
& unzip -o "$o" -d $d # GOOD [FALSE POSITIVE]
215+
& unzip -o "$o" -d $d # GOOD
216216
}

0 commit comments

Comments
 (0)