Skip to content

Commit f2f18fe

Browse files
author
dilanbhalla
committed
Merge branch 'main' of https://github.com/microsoft/codeql into auto/sync-main-pr
2 parents bd3f774 + 42104ec commit f2f18fe

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
private import AstImport
22

33
class Attribute extends AttributeBase, TAttribute {
4-
string getName() { result = getRawAst(this).(Raw::Attribute).getName() }
4+
string getLowerCaseName() { result = getRawAst(this).(Raw::Attribute).getName().toLowerCase() }
5+
6+
bindingset[result]
7+
string getAName() { result.toLowerCase() = this.getLowerCaseName() }
58

69
NamedAttributeArgument getNamedArgument(int i) {
710
exists(ChildIndex index, Raw::Ast r | index = attributeNamedArg(i) and r = getRawAst(this) |
@@ -41,7 +44,7 @@ class Attribute extends AttributeBase, TAttribute {
4144
result = this.toStringSpecific()
4245
or
4346
not exists(this.toStringSpecific()) and
44-
result = this.getName()
47+
result = this.getLowerCaseName()
4548
}
4649

4750
final override Ast getChild(ChildIndex i) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ class AttributeCfgNode extends AttributeBaseCfgNode {
180180
ExprCfgNode getPositionalArgument(int i) {
181181
attr.hasCfgChild(attr.getPositionalArgument(i), this, result)
182182
}
183+
184+
string getLowerCaseName() { result = attr.getLowerCaseName() }
185+
186+
bindingset[result]
187+
string getAName() { result = attr.getAName() }
183188
}
184189

185190
private class ScriptBlockChildMapping extends NonExprChildMapping, ScriptBlock {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ module CommandInjection {
240240
exists(Function f, Attribute a, Parameter p |
241241
p = f.getAParameter() and
242242
p.getAnAttribute() = a and
243-
a.getName() = ["ValidateScript", "ValidateSet", "ValidatePattern"] and
243+
a.getAName() = ["ValidateScript", "ValidateSet", "ValidatePattern"] and
244244
this.asParameter() = p
245245
)
246246
}

powershell/ql/src/queries/security/cwe-078/CommandInjectionCritical.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ abstract class CriticalSource extends DataFlow::Node {
2626
class CmdletBindingParam extends CriticalSource {
2727
CmdletBindingParam(){
2828
exists(Attribute a, Function f |
29-
a.getName() = "CmdletBinding" and
29+
a.getAName() = "CmdletBinding" and
3030
f = a.getEnclosingFunction() and
3131
this.asParameter() = f.getAParameter()
3232
)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@
116116
| Arrays/Arrays.ps1:15:1:15:14 | [Stmt] Call to add | Arrays/Arrays.ps1:1:1:15:14 | {...} |
117117
| Arrays/Arrays.ps1:15:9:15:11 | Add | Arrays/Arrays.ps1:15:1:15:14 | Call to add |
118118
| Arrays/Arrays.ps1:15:13:15:13 | 1 | Arrays/Arrays.ps1:15:1:15:14 | Call to add |
119-
| Blocks/ParamBlock.ps1:1:1:1:17 | CmdletBinding | Blocks/ParamBlock.ps1:1:1:5:1 | {...} |
119+
| Blocks/ParamBlock.ps1:1:1:1:17 | cmdletbinding | Blocks/ParamBlock.ps1:1:1:5:1 | {...} |
120120
| Blocks/ParamBlock.ps1:1:1:5:1 | [synth] pipeline | Blocks/ParamBlock.ps1:1:1:5:1 | {...} |
121121
| Blocks/ParamBlock.ps1:1:1:5:1 | {...} | Blocks/ParamBlock.ps1:1:1:5:1 | toplevel function for ParamBlock.ps1 |
122122
| Blocks/ParamBlock.ps1:2:1:5:1 | {...} | Blocks/ParamBlock.ps1:1:1:5:1 | {...} |
123-
| Blocks/ParamBlock.ps1:3:5:3:17 | Parameter | Blocks/ParamBlock.ps1:3:5:4:22 | parameter |
123+
| Blocks/ParamBlock.ps1:3:5:3:17 | parameter | Blocks/ParamBlock.ps1:3:5:4:22 | parameter |
124124
| Blocks/ParamBlock.ps1:3:5:4:22 | parameter | Blocks/ParamBlock.ps1:1:1:5:1 | {...} |
125125
| Blocks/ParamBlock.ps1:4:5:4:12 | string | Blocks/ParamBlock.ps1:3:5:4:22 | parameter |
126126
| Dynamic/DynamicExecution.ps1:1:1:1:4 | foo | Dynamic/DynamicExecution.ps1:1:1:1:16 | ...=... |
@@ -420,7 +420,7 @@
420420
| Statements/UseProcessBlockForPipelineCommand.ps1:1:1:11:1 | {...} | Statements/UseProcessBlockForPipelineCommand.ps1:1:1:11:1 | toplevel function for UseProcessBlockForPipelineCommand.ps1 |
421421
| Statements/UseProcessBlockForPipelineCommand.ps1:1:1:11:1 | {...} | Statements/UseProcessBlockForPipelineCommand.ps1:1:1:11:1 | {...} |
422422
| Statements/UseProcessBlockForPipelineCommand.ps1:2:1:11:1 | {...} | Statements/UseProcessBlockForPipelineCommand.ps1:1:1:11:1 | Get-Number |
423-
| Statements/UseProcessBlockForPipelineCommand.ps1:3:5:3:21 | CmdletBinding | Statements/UseProcessBlockForPipelineCommand.ps1:2:1:11:1 | {...} |
423+
| Statements/UseProcessBlockForPipelineCommand.ps1:3:5:3:21 | cmdletbinding | Statements/UseProcessBlockForPipelineCommand.ps1:2:1:11:1 | {...} |
424424
| Statements/UseProcessBlockForPipelineCommand.ps1:4:5:10:11 | {...} | Statements/UseProcessBlockForPipelineCommand.ps1:2:1:11:1 | {...} |
425425
| Statements/UseProcessBlockForPipelineCommand.ps1:5:9:5:38 | ValueFromPipeline | Statements/UseProcessBlockForPipelineCommand.ps1:5:9:7:15 | number |
426426
| Statements/UseProcessBlockForPipelineCommand.ps1:5:9:7:15 | number | Statements/UseProcessBlockForPipelineCommand.ps1:2:1:11:1 | {...} |

0 commit comments

Comments
 (0)