Skip to content

Commit 83b8f89

Browse files
authored
Merge pull request #292 from microsoft/fix-missing-variables
PS: Fix missing variables
2 parents 3759158 + 0e39139 commit 83b8f89

File tree

7 files changed

+43
-4
lines changed

7 files changed

+43
-4
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ private module EnvironmentVariableAccessSynth {
193193
)
194194
}
195195

196-
private predicate envVarAccess(Raw::Ast parent, ChildIndex i, Child child, Raw::VarAccess va, string var) {
196+
private predicate envVarAccess(
197+
Raw::Ast parent, ChildIndex i, Child child, Raw::VarAccess va, string var
198+
) {
197199
va = parent.getChild(toRawChildIndex(i)) and
198200
Raw::isEnvVariableAccess(va, var) and
199201
child = SynthChild(VarAccessSynthKind(TVariableSynth(_, EnvVar(var))))

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,22 @@ module Private {
140140
predicate explicitAssignment(Raw::Ast dest, Raw::Ast assignment) {
141141
assignment.(Raw::AssignStmt).getLeftHandSide() = dest
142142
or
143+
exists(Raw::ConvertExpr convert |
144+
convert.getExpr() = dest and
145+
explicitAssignment(convert, assignment)
146+
)
147+
or
143148
any(Synthesis s).explicitAssignment(dest, _, assignment)
144149
}
145150

146-
predicate implicitAssignment(Raw::Ast n) { any(Synthesis s).implicitAssignment(n, _) }
151+
predicate implicitAssignment(Raw::Ast n) {
152+
any(Synthesis s).implicitAssignment(n, _)
153+
or
154+
exists(Raw::ConvertExpr convert |
155+
convert.getExpr() = n and
156+
implicitAssignment(convert)
157+
)
158+
}
147159
}
148160

149161
private import Private

powershell/ql/lib/semmle/code/powershell/security/SqlInjectionCustomizations.qll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ module SqlInjection {
7979
override string getSinkType() { result = "call to Invoke-Sqlcmd" }
8080

8181
override predicate allowImplicitRead(DataFlow::ContentSet cs) {
82-
cs.getAStoreContent().(DataFlow::Content::KnownKeyContent).getIndex().asString().toLowerCase() =
83-
query()
82+
cs.getAStoreContent().(DataFlow::Content::KnownKeyContent).getIndex().stringMatches(query())
8483
}
8584
}
8685

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
$x = 42
2+
$x
3+
4+
[int]$y = 42
5+
$y
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.ps1:1:1:1:2 | x | test.ps1:2:1:2:2 | x |
2+
| test.ps1:4:6:4:7 | y | test.ps1:5:1:5:2 | y |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import powershell
2+
3+
query predicate variables(Variable v, VarReadAccess va) { va.getVariable() = v }

powershell/ql/test/library-tests/ast/parent.expected

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,19 @@
451451
| Strings/String.ps1:6:10:8:0 | '@\nkl | Strings/String.ps1:6:10:8:0 | Call to kl\n'@\n |
452452
| Strings/String.ps1:6:10:8:0 | Call to kl\n'@\n | Strings/String.ps1:6:10:8:0 | [Stmt] Call to kl\n'@\n |
453453
| Strings/String.ps1:6:10:8:0 | [Stmt] Call to kl\n'@\n | Strings/String.ps1:1:1:8:0 | {...} |
454+
| Variables/test.ps1:1:1:1:2 | x | Variables/test.ps1:1:1:1:7 | ...=... |
455+
| Variables/test.ps1:1:1:1:2 | x | Variables/test.ps1:1:1:5:2 | {...} |
456+
| Variables/test.ps1:1:1:1:7 | ...=... | Variables/test.ps1:1:1:5:2 | {...} |
457+
| Variables/test.ps1:1:1:5:2 | {...} | Variables/test.ps1:1:1:5:2 | toplevel function for test.ps1 |
458+
| Variables/test.ps1:1:1:5:2 | {...} | Variables/test.ps1:1:1:5:2 | {...} |
459+
| Variables/test.ps1:1:6:1:7 | 42 | Variables/test.ps1:1:1:1:7 | ...=... |
460+
| Variables/test.ps1:2:1:2:2 | [Stmt] x | Variables/test.ps1:1:1:5:2 | {...} |
461+
| Variables/test.ps1:2:1:2:2 | x | Variables/test.ps1:2:1:2:2 | [Stmt] x |
462+
| Variables/test.ps1:4:1:4:5 | int | Variables/test.ps1:4:1:4:7 | [...]... |
463+
| Variables/test.ps1:4:1:4:7 | [...]... | Variables/test.ps1:4:1:4:12 | ...=... |
464+
| Variables/test.ps1:4:1:4:12 | ...=... | Variables/test.ps1:1:1:5:2 | {...} |
465+
| Variables/test.ps1:4:6:4:7 | y | Variables/test.ps1:1:1:5:2 | {...} |
466+
| Variables/test.ps1:4:6:4:7 | y | Variables/test.ps1:4:1:4:7 | [...]... |
467+
| Variables/test.ps1:4:11:4:12 | 42 | Variables/test.ps1:4:1:4:12 | ...=... |
468+
| Variables/test.ps1:5:1:5:2 | [Stmt] y | Variables/test.ps1:1:1:5:2 | {...} |
469+
| Variables/test.ps1:5:1:5:2 | y | Variables/test.ps1:5:1:5:2 | [Stmt] y |

0 commit comments

Comments
 (0)