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 {
7272 /** Gets the name of the type being constructed by this constructor call. */
7373 string getConstructedTypeName ( ) { result = typename .getName ( ) }
7474}
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 {
587587 }
588588
589589 private class CallOperatorChildMapping extends CallExprChildMapping instanceof CallOperator {
590- override predicate relevantChild ( Ast child ) { none ( ) }
590+ override predicate relevantChild ( Ast child ) { super . relevantChild ( child ) }
591591 }
592592
593593 class CallOperatorCfgNode extends CallExprCfgNode {
@@ -600,6 +600,18 @@ module ExprNodes {
600600 ExprCfgNode getCommand ( ) { result = this .getArgument ( 0 ) }
601601 }
602602
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+
603615 private class MemberExprChildMapping extends ExprChildMapping , MemberExpr {
604616 override predicate relevantChild ( Ast child ) {
605617 child = this .getQualifier ( )
Original file line number Diff line number Diff line change @@ -534,6 +534,13 @@ class CallOperatorNode extends CallNode {
534534 Node getCommand ( ) { result .asExpr ( ) = call .getCommand ( ) } // TODO: Alternatively, we could remap calls to & as command expressions.
535535}
536536
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+
537544/** A use of a type name, viewed as a node in a data flow graph. */
538545class TypeNameNode extends ExprNode {
539546 override CfgNodes:: ExprNodes:: TypeNameExprCfgNode n ;
Original file line number Diff line number Diff line change @@ -57,6 +57,8 @@ private module Cached {
5757 or
5858 c .isAnyElement ( )
5959 )
60+ or
61+ nodeTo .( DataFlow:: ToStringCallNode ) .getQualifier ( ) = nodeFrom
6062 ) and
6163 model = ""
6264 or
You can’t perform that action at this time.
0 commit comments