Skip to content

Powershell: Fix dataflow/SSA consistency errors. #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2024
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
11 changes: 11 additions & 0 deletions powershell/ql/consistency-queries/DataFlowConsistency.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import semmle.code.powershell.dataflow.DataFlow::DataFlow as DataFlow
private import powershell
private import semmle.code.powershell.dataflow.internal.DataFlowImplSpecific
private import semmle.code.powershell.dataflow.internal.TaintTrackingImplSpecific
private import codeql.dataflow.internal.DataFlowImplConsistency

private module Input implements InputSig<Location, PowershellDataFlow> {
private import PowershellDataFlow
}

import MakeConsistency<Location, PowershellDataFlow, PowershellTaintTracking, Input>
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ abstract class NodeImpl extends Node {
}

private class ExprNodeImpl extends ExprNode, NodeImpl {
override CfgScope getCfgScope() { none() /* TODO */ }
override CfgScope getCfgScope() { result = this.getExprNode().getExpr().getEnclosingScope() }

override Location getLocationImpl() { result = this.getExprNode().getLocation() }

override string toStringImpl() { result = this.getExprNode().toString() }
}

private class StmtNodeImpl extends StmtNode, NodeImpl {
override CfgScope getCfgScope() { none() /* TODO */ }
override CfgScope getCfgScope() { result = this.getStmtNode().getStmt().getEnclosingScope() }

override Location getLocationImpl() { result = this.getStmtNode().getLocation() }

Expand All @@ -69,7 +69,9 @@ module SsaFlow {
Impl::Node asNode(Node n) {
n = TSsaNode(result)
or
result.(Impl::ExprNode).getExpr() = n.asExpr() // TODO: Statement nodes?
result.(Impl::ExprNode).getExpr() = n.asExpr()
or
result.(Impl::ExprNode).getExpr() = n.asStmt()
or
result.(Impl::ExprPostUpdateNode).getExpr() = n.(PostUpdateNode).getPreUpdateNode().asExpr()
or
Expand Down Expand Up @@ -371,7 +373,8 @@ private module ParameterNodes {
override Parameter getParameter() { result = parameter }

override predicate isParameterOf(DataFlowCallable c, ParameterPosition pos) {
exists(CfgScope callable | callable = c.asCfgScope() |
parameter.getDeclaringScope() = c.asCfgScope() and
(
pos.isKeyword(parameter.getName())
or
// Given a function f with parameters x, y we map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class ParameterExt extends TParameterExt {
private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInputSig {
class Parameter = ParameterExt;

class Expr extends Cfg::CfgNodes::ExprCfgNode {
class Expr extends Cfg::CfgNodes::AstCfgNode {
predicate hasCfgNode(SsaInput::BasicBlock bb, int i) { this = bb.getNode(i) }
}

Expand Down