File tree Expand file tree Collapse file tree 4 files changed +27
-3
lines changed
powershell/ql/lib/semmle/code/powershell Expand file tree Collapse file tree 4 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ class CallOperator extends CmdCall {
8383class DotSourcingOperator extends CmdCall {
8484 DotSourcingOperator ( ) { getRawAst ( this ) instanceof Raw:: DotSourcingOperator }
8585
86- Expr getPath ( ) { result = this .getCallee ( ) }
86+ Expr getCommand ( ) { result = this .getCallee ( ) }
8787}
8888
8989class JoinPath extends CmdCall {
Original file line number Diff line number Diff line change @@ -608,6 +608,21 @@ module ExprNodes {
608608 ExprCfgNode getCommand ( ) { result = this .getCallee ( ) }
609609 }
610610
611+ private class DotSourcingOperatorChildMapping extends CallExprChildMapping instanceof DotSourcingOperator
612+ {
613+ override predicate relevantChild ( Ast child ) { super .relevantChild ( child ) }
614+ }
615+
616+ class DotSourcingOperatorCfgNode extends CallExprCfgNode {
617+ override string getAPrimaryQlClass ( ) { result = "DotSourcingOperatorCfgNode" }
618+
619+ override DotSourcingOperatorChildMapping e ;
620+
621+ override DotSourcingOperator getExpr ( ) { result = e }
622+
623+ ExprCfgNode getCommand ( ) { result = this .getCallee ( ) }
624+ }
625+
611626 private class ToStringCallChildmapping extends CallExprChildMapping instanceof ToStringCall {
612627 override predicate relevantChild ( Ast child ) { super .relevantChild ( child ) }
613628 }
Original file line number Diff line number Diff line change @@ -544,7 +544,14 @@ class CallNode extends ExprNode {
544544class CallOperatorNode extends CallNode {
545545 override CfgNodes:: ExprNodes:: CallOperatorCfgNode call ;
546546
547- Node getCommand ( ) { result .asExpr ( ) = call .getCommand ( ) } // TODO: Alternatively, we could remap calls to & as command expressions.
547+ Node getCommand ( ) { result .asExpr ( ) = call .getCommand ( ) }
548+ }
549+
550+ /** A call to operator `.`, viewed as a node in a data flow graph. */
551+ class DotSourcingOperatorNode extends CallNode {
552+ override CfgNodes:: ExprNodes:: DotSourcingOperatorCfgNode call ;
553+
554+ Node getCommand ( ) { result .asExpr ( ) = call .getCommand ( ) }
548555}
549556
550557/**
Original file line number Diff line number Diff line change @@ -46,8 +46,10 @@ module CommandInjection {
4646 call .getAnArgument ( ) = this
4747 )
4848 or
49- // Or the call command itself in case it's a use of operator &.
49+ // Or the call command itself in case it's a use of " operator &" or "operator ." .
5050 any ( DataFlow:: CallOperatorNode call ) .getCommand ( ) = this
51+ or
52+ any ( DataFlow:: DotSourcingOperatorNode call ) .getCommand ( ) = this
5153 }
5254
5355 override string getSinkType ( ) { result = "call to Invoke-Expression" }
You can’t perform that action at this time.
0 commit comments