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
25 changes: 25 additions & 0 deletions unified/ql/lib/codeql/unified/internal/AnalysisQuality.qll
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,28 @@
}

module CallGraphStatsReport = EntityReportStats<CallGraphStats>;

/**
* Gets summary statistics about taint.
*/
predicate taintStats(string key, int value) {
// The keys must match those in DCA summary profiles
key = "Taint sources - active" and value = count(DataFlow::Node n | Models::isSource(n, "remote"))
or
key = "Taint sources - disabled" and
value = count(DataFlow::Node n | Models::isSource(n, any(string s | s != "remote")))
or
key = "Taint sources - sensitive data" and none()
Comment on lines +117 to +122
or
key = "Taint edges - number of edges" and none()
or
key = "Taint reach - nodes tainted" and none()
or
key = "Taint reach - total non-summary nodes" and none()
or
key = "Taint reach - per million nodes" and none()
or
key = "Taint sinks - query sinks" and value = count(DataFlow::Node n | Models::isSink(n, _))
Comment on lines +117 to +132
or
key = "Taint sinks - cryptographic operations" and none()
}
13 changes: 13 additions & 0 deletions unified/ql/lib/codeql/unified/internal/FacadeAst.qll
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ overlay[local?]
module;

private import codeql.files.FileSystem
private import codeql.unified.internal.NameBinding as NameBinding

module Unified {
private import Ast::Unified as G
Expand Down Expand Up @@ -145,6 +146,13 @@ module Unified {
class ClassLikeDeclaration extends G::ClassLikeDeclaration {
/** Gets the name of this declaration. */
string getName() { result = this.getNameNode().getValue() }

/** Gets a direct base class of this class. */
ClassLikeDeclaration getABaseClass() {
result.getNameNode() =
NameBinding::getStaticBindingTarget(NameBinding::getIdentifierFromRef(this.getABaseType()
.getType()))
}
}

class ConstructorDeclaration extends G::ConstructorDeclaration {
Expand Down Expand Up @@ -260,5 +268,10 @@ module Unified {

/** Gets the number of arguments passed to this call, not counting implicit arguments like receiver. */
int getNumberOfArguments() { result = count(this.getAnArgument()) }

/** Gets the number of positional arguments passed to this call. */
int getNumberOfPositionalArguments() {
result = count(Argument arg | arg = this.getAnArgument() and arg.isPositional())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ module DebugGraph<relevantNodeSig/1 relevantNode> {
if isUseStep = true then value = "use-use" else value = "def-use"
)
or
node2 = getPostUpdateNode(node1) and
node2 = node1.getPostUpdateNode() and
value = "post-update"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ module DataFlowInput implements InputSig<Location> {
// Post-update nodes
//
class PostUpdateNode extends Node {
PostUpdateNode() { this = getPostUpdateNode(_) }
PostUpdateNode() { this = any(Node n).getPostUpdateNode() }

Node getPreUpdateNode() { this = getPostUpdateNode(result) }
Node getPreUpdateNode() { this = result.getPostUpdateNode() }
}

//
Expand Down
38 changes: 22 additions & 16 deletions unified/ql/lib/codeql/unified/internal/dataflow/DataFlowNode.qll
Original file line number Diff line number Diff line change
Expand Up @@ -315,21 +315,27 @@ class Node extends TDataFlowNode {

/** Gets the basic block associated with this data flow node, if any. */
BasicBlock getBasicBlock() { this.hasControlFlowPosition(result, _) }
}

Node getPostUpdateNode(Node pre) {
exists(Expr expr |
pre.isResultValue(expr) and
result.isPostUpdate(expr)
)
or
exists(Expr expr, LocalVariable var |
pre.isLocalVariableRead(expr, var) and
result.isLocalVariablePostUpdate(expr, var)
)
or
exists(DataFlowCall call |
pre.isReceiverArgumentEx(call) and
result.isReceiverPostUpdateEx(call)
)
/**
* Gets the post-update node for this node, if any.
*
* The post-update node represents the updated state of the value held in this node, after it has been mutated by the surrounding assignment or call.
*/
pragma[nomagic]
Node getPostUpdateNode() {
exists(Expr expr |
this.isResultValue(expr) and
result.isPostUpdate(expr)
)
or
exists(Expr expr, LocalVariable var |
this.isLocalVariableRead(expr, var) and
result.isLocalVariablePostUpdate(expr, var)
)
or
exists(DataFlowCall call |
this.isReceiverArgumentEx(call) and
result.isReceiverPostUpdateEx(call)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Node getNodeFromLocalSsaNode(Ssa::Node n) {
result = n.(Ssa::ExprNode).getExpr() and
not postUpdateReadNode(n)
or
result = getPostUpdateNode(n.(Ssa::ExprPostUpdateNode).getExpr())
result = n.(Ssa::ExprPostUpdateNode).getExpr().(Node).getPostUpdateNode()
or
exists(LocalVariable v, BasicBlock bb, int i, AstNode repr |
n.(Ssa::WriteDefSourceNode).getDefinition().definesAt(v, bb, i) and
Expand Down
Loading
Loading