Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions powershell/ql/lib/semmle/code/powershell/ApiGraphs.qll
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ module API {
predicate toplevelCall(string name, Node node) {
exists(DataFlow::CallNode call |
call.asExpr().getExpr().getEnclosingScope() instanceof TopLevelScriptBlock and
call.getName() = name and
call.getLowerCaseName() = name and
node = MkMethodAccessNode(call)
)
}
Expand All @@ -522,7 +522,7 @@ module API {
// from receiver to method call node
pred = getForwardEndNode(getALocalSourceStrict(call.getQualifier())) and
succ = MkMethodAccessNode(call) and
name = call.getName()
name = call.getLowerCaseName()
)
}

Expand All @@ -549,7 +549,7 @@ module API {
_)
|
result = MkMethodAccessNode(call) and
name = call.getName().toLowerCase()
name = call.getLowerCaseName()
)
}

Expand Down Expand Up @@ -586,7 +586,7 @@ module API {
cached
predicate methodEdge(Node pred, string name, Node succ) {
exists(DataFlow::CallNode call |
succ = MkMethodAccessNode(call) and name = call.getName().toLowerCase()
succ = MkMethodAccessNode(call) and name = call.getLowerCaseName()
|
pred = getForwardEndNode(getALocalSourceStrict(call.getQualifier()))
)
Expand Down
24 changes: 21 additions & 3 deletions powershell/ql/lib/semmle/code/powershell/ast/internal/CallExpr.qll
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ class CallExpr extends Expr, TCallExpr {
Expr getArgument(int i) { none() }

/** Gets the name that is used to select the callee. */
string getName() { none() }
string getLowerCaseName() { none() }

/** Holds if `name` is the name of this call. The name is case insensitive. */
bindingset[name]
pragma[inline_late]
final predicate matchesName(string name) { this.getLowerCaseName() = name.toLowerCase() }

/** Gets a name that case-insensitively matches the name of this call. */
bindingset[result]
pragma[inline_late]
final string getAName() { result.toLowerCase() = this.getLowerCaseName() }

/** Gets the i'th positional argument to this call. */
Expr getPositionalArgument(int i) { none() }
Expand All @@ -32,7 +42,7 @@ class CallExpr extends Expr, TCallExpr {
exists(Pipeline p, int i | this = p.getComponent(i + 1) and result = p.getComponent(i))
}

final override string toString() { result = "Call to " + this.getName() }
final override string toString() { result = "Call to " + this.getLowerCaseName() }

predicate isStatic() { none() }
}
Expand All @@ -44,7 +54,15 @@ class Argument extends Expr {

int getPosition() { this = call.getPositionalArgument(result) }

string getName() { this = call.getNamedArgument(result) }
string getLowerCaseName() { this = call.getNamedArgument(result) }

bindingset[name]
pragma[inline_late]
final predicate matchesName(string name) { this.getLowerCaseName() = name.toLowerCase() }

bindingset[result]
pragma[inline_late]
final string getAName() { result.toLowerCase() = this.getLowerCaseName() }

CallExpr getCall() { result = call }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ newtype ChildIndex =
RealVar(string name) { name = variableNameInScope(_, _) } or
ProcessBlockPipelineVarReadAccess() or
ProcessBlockPipelineByPropertyNameVarReadAccess(string name) {
name = any(Raw::PipelineByPropertyNameParameter p).getName()
name = any(Raw::PipelineByPropertyNameParameter p).getLowerCaseName()
}

int synthPipelineParameterChildIndex(Raw::ScriptBlock sb) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
private import AstImport

class CmdCall extends CallExpr, TCmd {
final override string getName() { result = getRawAst(this).(Raw::Cmd).getCommandName() }
final override string getLowerCaseName() { result = getRawAst(this).(Raw::Cmd).getLowerCaseName() }

final override Expr getArgument(int i) { synthChild(getRawAst(this), cmdArgument(i), result) }

Expand Down Expand Up @@ -85,7 +85,7 @@ class DotSourcingOperator extends CmdCall {
}

class JoinPath extends CmdCall {
JoinPath() { this.getName().toLowerCase() = "join-path" }
JoinPath() { this.getLowerCaseName() = "join-path" }

Expr getPath() {
result = this.getNamedArgument("path")
Expand All @@ -103,7 +103,7 @@ class JoinPath extends CmdCall {
}

class SplitPath extends CmdCall {
SplitPath() { this.getName().toLowerCase() = "split-path" }
SplitPath() { this.getLowerCaseName() = "split-path" }

Expr getPath() {
result = this.getNamedArgument("path")
Expand Down Expand Up @@ -131,7 +131,7 @@ class SplitPath extends CmdCall {
}

class GetVariable extends CmdCall {
GetVariable() { this.getName().toLowerCase() = "get-variable" }
GetVariable() { this.getLowerCaseName() = "get-variable" }

Expr getVariable() { result = this.getPositionalArgument(0) }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
private import AstImport

class InvokeMemberExpr extends CallExpr, TInvokeMemberExpr {
final override string getName() { result = getRawAst(this).(Raw::InvokeMemberExpr).getName() }
final override string getLowerCaseName() {
result = getRawAst(this).(Raw::InvokeMemberExpr).getLowerCaseName()
}

final override Ast getChild(ChildIndex i) {
result = super.getChild(i)
Expand Down Expand Up @@ -66,7 +68,7 @@ class ConstructorCall extends InvokeMemberExpr {
TypeNameExpr typename;

ConstructorCall() {
this.isStatic() and typename = this.getQualifier() and this.getName() = "new"
this.isStatic() and typename = this.getQualifier() and this.getLowerCaseName() = "new"
}

/** Gets the name of the type being constructed by this constructor call. */
Expand All @@ -81,5 +83,5 @@ class ConstructorCall extends InvokeMemberExpr {
* ```
*/
class ToStringCall extends InvokeMemberExpr {
ToStringCall() { this.getName().toLowerCase() = "toString" }
ToStringCall() { this.getLowerCaseName() = "tostring" }
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ProcessBlock extends NamedBlock {

PipelineByPropertyNameParameter getPipelineByPropertyNameParameter(string name) {
result = scriptBlock.getAParameter() and
result.getPropertyName() = name
result.getLowerCaseName() = name
}

PipelineByPropertyNameParameter getAPipelineByPropertyNameParameter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class NewObjectCreation extends AbstractObjectCreation, ConstructorCall {
* ```
*/
class DotNetObjectCreation extends AbstractObjectCreation, CmdCall {
DotNetObjectCreation() { this.getName() = "New-Object" }
DotNetObjectCreation() { this.getLowerCaseName() = "new-object" }

final override string getConstructedTypeName() {
result = this.getConstructedTypeExpr().(StringConstExpr).getValueString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
private import AstImport

class Parameter extends Variable instanceof ParameterImpl {
string getName() { result = super.getNameImpl() }
string getLowerCaseName() { result = super.getLowerCaseNameImpl() }

final predicate hasName(string name) { name = this.getName() }
bindingset[name]
pragma[inline_late]
final predicate matchesName(string name) { this.getLowerCaseName() = name.toLowerCase() }

bindingset[result]
pragma[inline_late]
final string getAName() { result.toLowerCase() = this.getLowerCaseName() }

override Ast getChild(ChildIndex childIndex) {
result = Variable.super.getChild(childIndex)
Expand Down Expand Up @@ -41,7 +47,7 @@ class PipelineParameter extends Parameter instanceof PipelineParameterImpl {

/**
* The iterator variable associated with a pipeline parameter.
*
*
* This is the variable that is bound to the current element in the pipeline.
*/
class PipelineIteratorVariable extends Variable instanceof PipelineIteratorVariableImpl {
Expand All @@ -55,8 +61,6 @@ class PipelineByPropertyNameParameter extends Parameter instanceof PipelineByPro
{
ScriptBlock getScriptBlock() { result = super.getScriptBlock() }

string getPropertyName() { result = super.getName() }

/**
* Gets the iterator variable that is used to iterate over the elements in the pipeline.
*/
Expand All @@ -65,7 +69,7 @@ class PipelineByPropertyNameParameter extends Parameter instanceof PipelineByPro

/**
* The iterator variable associated with a pipeline-by-property-name parameter.
*
*
* This is the variable that is bound to the current element in the pipeline.
*/
class PipelineByPropertyNameIteratorVariable extends Variable instanceof PipelineByPropertyNameIteratorVariableImpl
Expand All @@ -79,4 +83,4 @@ class PipelineByPropertyNameIteratorVariable extends Variable instanceof Pipelin
* iterates over.
*/
PipelineByPropertyNameParameter getParameter() { result = super.getParameter() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ private import Raw

private predicate parseCommandName(Cmd cmd, string namespace, string name) {
exists(string qualified | command(cmd, qualified, _, _, _) |
namespace = qualified.regexpCapture("([^\\\\]+)\\\\([^\\\\]+)", 1) and
name = qualified.regexpCapture("([^\\\\]+)\\\\([^\\\\]+)", 2)
namespace = qualified.regexpCapture("([^\\\\]+)\\\\([^\\\\]+)", 1).toLowerCase() and
name = qualified.regexpCapture("([^\\\\]+)\\\\([^\\\\]+)", 2).toLowerCase()
or
// Not a qualified name
not exists(qualified.indexOf("\\")) and
namespace = "" and
name = qualified
name = qualified.toLowerCase()
)
}

Expand All @@ -30,7 +30,15 @@ class Cmd extends @command, CmdBase {
CmdElement getCallee() { result = this.getElement(0) }

/** Gets the name of the command without any qualifiers. */
string getCommandName() { parseCommandName(this, _, result) }
string getLowerCaseName() { parseCommandName(this, _, result) }

bindingset[name]
pragma[inline_late]
final predicate matchesName(string name) { this.getLowerCaseName() = name.toLowerCase() }

bindingset[result]
pragma[inline_late]
final string getAName() { result.toLowerCase() = this.getLowerCaseName() }

/** Holds if the command is qualified. */
predicate isQualified() { parseCommandName(this, any(string s | s != ""), _) }
Expand Down Expand Up @@ -70,7 +78,7 @@ class Cmd extends @command, CmdBase {
// sourcing operator) the 0'th element is not the command name, but
// rather the thing to invoke. These all appear to be commands with
// an empty string as the command name.
this.getCommandName() = ""
this.matchesName("")
) and
e = this.getElement(j) and
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ class InvokeMemberExpr extends @invoke_member_expression, MemberExprBase {

Expr getQualifier() { invoke_member_expression(this, result, _) }

string getName() { result = this.getCallee().(StringConstExpr).getValue().getValue() }

Expr getCallee() { invoke_member_expression(this, _, result) }

string getMemberName() { result = this.getCallee().(StringConstExpr).getValue().getValue() }
string getLowerCaseName() { result = this.getCallee().(StringConstExpr).getValue().getValue().toLowerCase() }

Expr getArgument(int i) { invoke_member_expression_argument(this, i, result) }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
private import Raw

class Parameter extends @parameter, Ast {
string getName() {
exists(@variable_expression va |
string getLowerCaseName() {
exists(@variable_expression va, string userPath |
parameter(this, va, _, _) and
variable_expression(va, result, _, _, _, _, _, _, _, _, _, _)
variable_expression(va, userPath, _, _, _, _, _, _, _, _, _, _) and
result = userPath.toLowerCase()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ Scope scopeOf(Ast n) {
)
}

module Parameter {
abstract class Scope extends Ast {
abstract string getName();
}

private class ParameterScope extends Scope instanceof Parameter {
final override string getName() { result = Parameter.super.getName() }
}
}

abstract private class ScopeImpl extends Ast {
abstract Scope getOuterScopeImpl();

Expand Down
Loading