Skip to content

Commit a6a1734

Browse files
committed
PS: Easier debugging with strings for child indices.
1 parent 7102ebb commit a6a1734

File tree

5 files changed

+271
-4
lines changed

5 files changed

+271
-4
lines changed

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,67 @@ int synthPipelineParameterChildIndex(Raw::ScriptBlock sb) {
4646
)
4747
}
4848

49+
string stringOfChildIndex(ChildIndex i) {
50+
exists(Raw::ChildIndex rawIndex |
51+
i = RawChildIndex(rawIndex) and
52+
result = Raw::stringOfChildIndex(rawIndex)
53+
)
54+
or
55+
i = ParamPipeline() and
56+
result = "ParamPipeline"
57+
or
58+
i = ParamDefaultVal() and
59+
result = "ParamDefaultVal"
60+
or
61+
i = FunParam(_) and
62+
result = "FunParam"
63+
or
64+
i = CmdArgument(_) and
65+
result = "CmdArgument"
66+
or
67+
i = ExprStmtExpr() and
68+
result = "ExprStmtExpr"
69+
or
70+
i = MethodBody() and
71+
result = "MethodBody"
72+
or
73+
i = ThisVar() and
74+
result = "ThisVar"
75+
or
76+
i = PipelineParamVar() and
77+
result = "PipelineParamVar"
78+
or
79+
i = PipelineIteratorVar() and
80+
result = "PipelineIteratorVar"
81+
or
82+
i = PipelineByPropertyNameIteratorVar(_) and
83+
result = "PipelineByPropertyNameIteratorVar"
84+
or
85+
i = RealVar(_) and
86+
result = "RealVar"
87+
or
88+
i = ExprRedirection(_) and
89+
result = "ExprRedirection"
90+
or
91+
i = FunDefFun() and
92+
result = "FunDefFun"
93+
or
94+
i = TypeDefType() and
95+
result = "TypeDefType"
96+
or
97+
i = TypeMember(_) and
98+
result = "TypeMember"
99+
or
100+
i = ScriptBlockAttr(_) and
101+
result = "ScriptBlockAttr"
102+
or
103+
i = ParamAttr(_) and
104+
result = "ParamAttr"
105+
or
106+
i = FunctionBody() and
107+
result = "FunctionBody"
108+
}
109+
49110
Raw::ChildIndex toRawChildIndex(ChildIndex i) { i = RawChildIndex(result) }
50111

51112
ChildIndex arrayExprStmtBlock() { result = RawChildIndex(Raw::ArrayExprStmtBlock()) }

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

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,201 @@ newtype ChildIndex =
9999
UsingExprExpr() or
100100
WhileStmtCond() or
101101
WhileStmtBody()
102+
103+
string stringOfChildIndex(ChildIndex i) {
104+
i = ArrayExprStmtBlock() and result = "ArrayExprStmtBlock"
105+
or
106+
i = ArrayLiteralExpr(_) and result = "ArrayLiteralExpr"
107+
or
108+
i = AssignStmtLeftHandSide() and result = "AssignStmtLeftHandSide"
109+
or
110+
i = AssignStmtRightHandSide() and result = "AssignStmtRightHandSide"
111+
or
112+
i = AttributeNamedArg(_) and result = "AttributeNamedArg"
113+
or
114+
i = AttributePosArg(_) and result = "AttributePosArg"
115+
or
116+
i = AttributedExprExpr() and result = "AttributedExprExpr"
117+
or
118+
i = AttributedExprAttr() and result = "AttributedExprAttr"
119+
or
120+
i = BinaryExprLeft() and result = "BinaryExprLeft"
121+
or
122+
i = BinaryExprRight() and result = "BinaryExprRight"
123+
or
124+
i = CatchClauseBody() and result = "CatchClauseBody"
125+
or
126+
i = CatchClauseType(_) and result = "CatchClauseType"
127+
or
128+
i = CmdElement_(_) and result = "CmdElement"
129+
or
130+
i = CmdCallee() and result = "CmdCallee"
131+
or
132+
i = CmdRedirection(_) and result = "CmdRedirection"
133+
or
134+
i = CmdExprExpr() and result = "CmdExprExpr"
135+
or
136+
i = ConfigurationName() and result = "ConfigurationName"
137+
or
138+
i = ConfigurationBody() and result = "ConfigurationBody"
139+
or
140+
i = ConvertExprExpr() and result = "ConvertExprExpr"
141+
or
142+
i = ConvertExprType() and result = "ConvertExprType"
143+
or
144+
i = ConvertExprAttr() and result = "ConvertExprAttr"
145+
or
146+
i = DataStmtBody() and result = "DataStmtBody"
147+
or
148+
i = DataStmtCmdAllowed(_) and result = "DataStmtCmdAllowed"
149+
or
150+
i = DoUntilStmtCond() and result = "DoUntilStmtCond"
151+
or
152+
i = DoUntilStmtBody() and result = "DoUntilStmtBody"
153+
or
154+
i = DoWhileStmtCond() and result = "DoWhileStmtCond"
155+
or
156+
i = DoWhileStmtBody() and result = "DoWhileStmtBody"
157+
or
158+
i = DynamicStmtName() and result = "DynamicStmtName"
159+
or
160+
i = DynamicStmtBody() and result = "DynamicStmtBody"
161+
or
162+
i = ExitStmtPipeline() and result = "ExitStmtPipeline"
163+
or
164+
i = ExpandableStringExprExpr(_) and result = "ExpandableStringExprExpr"
165+
or
166+
i = ForEachStmtVar() and result = "ForEachStmtVar"
167+
or
168+
i = ForEachStmtIter() and result = "ForEachStmtIter"
169+
or
170+
i = ForEachStmtBody() and result = "ForEachStmtBody"
171+
or
172+
i = ForStmtInit() and result = "ForStmtInit"
173+
or
174+
i = ForStmtCond() and result = "ForStmtCond"
175+
or
176+
i = ForStmtIter() and result = "ForStmtIter"
177+
or
178+
i = ForStmtBody() and result = "ForStmtBody"
179+
or
180+
i = FunDefStmtBody() and result = "FunDefStmtBody"
181+
or
182+
i = FunDefStmtParam(_) and result = "FunDefStmtParam"
183+
or
184+
i = GotoStmtLabel() and result = "GotoStmtLabel"
185+
or
186+
i = HashTableExprKey(_) and result = "HashTableExprKey"
187+
or
188+
i = HashTableExprStmt(_) and result = "HashTableExprStmt"
189+
or
190+
i = IfStmtElse() and result = "IfStmtElse"
191+
or
192+
i = IfStmtCond(_) and result = "IfStmtCond"
193+
or
194+
i = IfStmtThen(_) and result = "IfStmtThen"
195+
or
196+
i = IndexExprIndex() and result = "IndexExprIndex"
197+
or
198+
i = IndexExprBase() and result = "IndexExprBase"
199+
or
200+
i = InvokeMemberExprQual() and result = "InvokeMemberExprQual"
201+
or
202+
i = InvokeMemberExprCallee() and result = "InvokeMemberExprCallee"
203+
or
204+
i = InvokeMemberExprArg(_) and result = "InvokeMemberExprArg"
205+
or
206+
i = MemberExprQual() and result = "MemberExprQual"
207+
or
208+
i = MemberExprMember() and result = "MemberExprMember"
209+
or
210+
i = NamedAttributeArgVal() and result = "NamedAttributeArgVal"
211+
or
212+
i = MemberAttr(_) and result = "MemberAttr"
213+
or
214+
i = MemberTypeConstraint() and result = "MemberTypeConstraint"
215+
or
216+
i = NamedBlockStmt(_) and result = "NamedBlockStmt"
217+
or
218+
i = NamedBlockTrap(_) and result = "NamedBlockTrap"
219+
or
220+
i = ParamBlockAttr(_) and result = "ParamBlockAttr"
221+
or
222+
i = ParamBlockParam(_) and result = "ParamBlockParam"
223+
or
224+
i = ParamAttr(_) and result = "ParamAttr"
225+
or
226+
i = ParamDefaultVal() and result = "ParamDefaultVal"
227+
or
228+
i = ParenExprExpr() and result = "ParenExprExpr"
229+
or
230+
i = PipelineComp(_) and result = "PipelineComp"
231+
or
232+
i = PipelineChainLeft() and result = "PipelineChainLeft"
233+
or
234+
i = PipelineChainRight() and result = "PipelineChainRight"
235+
or
236+
i = ReturnStmtPipeline() and result = "ReturnStmtPipeline"
237+
or
238+
i = RedirectionExpr() and result = "RedirectionExpr"
239+
or
240+
i = ScriptBlockUsing(_) and result = "ScriptBlockUsing"
241+
or
242+
i = ScriptBlockParamBlock() and result = "ScriptBlockParamBlock"
243+
or
244+
i = ScriptBlockBeginBlock() and result = "ScriptBlockBeginBlock"
245+
or
246+
i = ScriptBlockCleanBlock() and result = "ScriptBlockCleanBlock"
247+
or
248+
i = ScriptBlockDynParamBlock() and result = "ScriptBlockDynParamBlock"
249+
or
250+
i = ScriptBlockEndBlock() and result = "ScriptBlockEndBlock"
251+
or
252+
i = ScriptBlockProcessBlock() and result = "ScriptBlockProcessBlock"
253+
or
254+
i = ScriptBlockExprBody() and result = "ScriptBlockExprBody"
255+
or
256+
i = StmtBlockStmt(_) and result = "StmtBlockStmt"
257+
or
258+
i = StmtBlockTrapStmt(_) and result = "StmtBlockTrapStmt"
259+
or
260+
i = ExpandableSubExprExpr() and result = "ExpandableSubExprExpr"
261+
or
262+
i = SwitchStmtCond() and result = "SwitchStmtCond"
263+
or
264+
i = SwitchStmtDefault() and result = "SwitchStmtDefault"
265+
or
266+
i = SwitchStmtCase(_) and result = "SwitchStmtCase"
267+
or
268+
i = SwitchStmtPat(_) and result = "SwitchStmtPat"
269+
or
270+
i = CondExprCond() and result = "CondExprCond"
271+
or
272+
i = CondExprTrue() and result = "CondExprTrue"
273+
or
274+
i = CondExprFalse() and result = "CondExprFalse"
275+
or
276+
i = ThrowStmtPipeline() and result = "ThrowStmtPipeline"
277+
or
278+
i = TryStmtBody() and result = "TryStmtBody"
279+
or
280+
i = TryStmtCatchClause(_) and result = "TryStmtCatchClause"
281+
or
282+
i = TryStmtFinally() and result = "TryStmtFinally"
283+
or
284+
i = TypeStmtMember(_) and result = "TypeStmtMember"
285+
or
286+
i = TypeStmtBaseType(_) and result = "TypeStmtBaseType"
287+
or
288+
i = TrapStmtBody() and result = "TrapStmtBody"
289+
or
290+
i = TrapStmtTypeConstraint() and result = "TrapStmtTypeConstraint"
291+
or
292+
i = UnaryExprOp() and result = "UnaryExprOp"
293+
or
294+
i = UsingExprExpr() and result = "UsingExprExpr"
295+
or
296+
i = WhileStmtCond() and result = "WhileStmtCond"
297+
or
298+
i = WhileStmtBody() and result = "WhileStmtBody"
299+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class PipelineParameter extends Parameter {
3535
this.getAnAttribute().(Attribute).getANamedArgument() = namedAttribute and
3636
namedAttribute.getName().toLowerCase() = "valuefrompipeline"
3737
|
38-
namedAttribute.getValue().(ConstExpr).getValue().getValue() = "true"
38+
namedAttribute.getValue().(ConstExpr).getValue().getValue().toLowerCase() = "true"
3939
or
4040
not exists(namedAttribute.getValue().(ConstExpr).getValue().getValue())
4141
)
@@ -50,7 +50,7 @@ class PipelineByPropertyNameParameter extends Parameter {
5050
this.getAnAttribute().(Attribute).getANamedArgument() = namedAttribute and
5151
namedAttribute.getName().toLowerCase() = "valuefrompipelinebypropertyname"
5252
|
53-
namedAttribute.getValue().(ConstExpr).getValue().getValue() = "true"
53+
namedAttribute.getValue().(ConstExpr).getValue().getValue().toLowerCase() = "true"
5454
or
5555
not exists(namedAttribute.getValue().(ConstExpr).getValue().getValue())
5656
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ module Private {
100100

101101
final override Variable getVariableImpl() { access(va, result) }
102102

103-
final override string toString() { result = va.getUserPath() }
103+
final override string toString() { result = "access to " + va.getUserPath() }
104104
}
105105

106106
class VarAccessSynth extends VarAccessImpl, TVarAccessSynth {
@@ -111,7 +111,7 @@ module Private {
111111

112112
final override Variable getVariableImpl() { any(Synthesis s).getAnAccess(this, result) }
113113

114-
final override string toString() { result = this.getVariableImpl().getName() }
114+
final override string toString() { result = "access to " + this.getVariableImpl().getName() }
115115

116116
final override Location getLocation() { result = parent.getLocation() }
117117
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,14 @@ class ProcessBlockCfgNode extends NamedBlockCfgNode {
282282
override ProcessBlock getBlock() { result = block }
283283

284284
ScriptBlockCfgNode getScriptBlock() { result.getProcessBlock() = this }
285+
286+
PipelineVariable getPipelineVariable() {
287+
result.getScriptBlock() = this.getScriptBlock().getAstNode()
288+
}
289+
290+
PipelineIteratorVariable getPipelineIteratorVariable() {
291+
result.getProcessBlock().getScriptBlock() = this.getScriptBlock().getAstNode()
292+
}
285293
}
286294

287295
private class CatchClauseChildMapping extends NonExprChildMapping, CatchClause {

0 commit comments

Comments
 (0)