File tree Expand file tree Collapse file tree 4 files changed +33
-1
lines changed
powershell/ql/lib/semmle/code/powershell Expand file tree Collapse file tree 4 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -72,3 +72,14 @@ class ConstructorCall extends InvokeMemberExpr {
72
72
/** Gets the name of the type being constructed by this constructor call. */
73
73
string getConstructedTypeName ( ) { result = typename .getName ( ) }
74
74
}
75
+
76
+ /**
77
+ * A call to a `toString` method. For example:
78
+ *
79
+ * ```powershell
80
+ * $x.ToString()
81
+ * ```
82
+ */
83
+ class ToStringCall extends InvokeMemberExpr {
84
+ ToStringCall ( ) { this .getName ( ) .toLowerCase ( ) = "toString" }
85
+ }
Original file line number Diff line number Diff line change @@ -587,7 +587,7 @@ module ExprNodes {
587
587
}
588
588
589
589
private class CallOperatorChildMapping extends CallExprChildMapping instanceof CallOperator {
590
- override predicate relevantChild ( Ast child ) { none ( ) }
590
+ override predicate relevantChild ( Ast child ) { super . relevantChild ( child ) }
591
591
}
592
592
593
593
class CallOperatorCfgNode extends CallExprCfgNode {
@@ -600,6 +600,18 @@ module ExprNodes {
600
600
ExprCfgNode getCommand ( ) { result = this .getArgument ( 0 ) }
601
601
}
602
602
603
+ private class ToStringCallChildmapping extends CallExprChildMapping instanceof ToStringCall {
604
+ override predicate relevantChild ( Ast child ) { super .relevantChild ( child ) }
605
+ }
606
+
607
+ class ToStringCallCfgNode extends CallExprCfgNode {
608
+ override string getAPrimaryQlClass ( ) { result = "ToStringCallCfgNode" }
609
+
610
+ override ToStringCallChildmapping e ;
611
+
612
+ override ToStringCall getExpr ( ) { result = e }
613
+ }
614
+
603
615
private class MemberExprChildMapping extends ExprChildMapping , MemberExpr {
604
616
override predicate relevantChild ( Ast child ) {
605
617
child = this .getQualifier ( )
Original file line number Diff line number Diff line change @@ -534,6 +534,13 @@ class CallOperatorNode extends CallNode {
534
534
Node getCommand ( ) { result .asExpr ( ) = call .getCommand ( ) } // TODO: Alternatively, we could remap calls to & as command expressions.
535
535
}
536
536
537
+ /**
538
+ * A call to `ToString`, viewed as a node in a data flow graph.
539
+ */
540
+ class ToStringCallNode extends CallNode {
541
+ override CfgNodes:: ExprNodes:: ToStringCallCfgNode call ;
542
+ }
543
+
537
544
/** A use of a type name, viewed as a node in a data flow graph. */
538
545
class TypeNameNode extends ExprNode {
539
546
override CfgNodes:: ExprNodes:: TypeNameExprCfgNode n ;
Original file line number Diff line number Diff line change @@ -57,6 +57,8 @@ private module Cached {
57
57
or
58
58
c .isAnyElement ( )
59
59
)
60
+ or
61
+ nodeTo .( DataFlow:: ToStringCallNode ) .getQualifier ( ) = nodeFrom
60
62
) and
61
63
model = ""
62
64
or
You can’t perform that action at this time.
0 commit comments