Skip to content

Commit ccaf910

Browse files
authored
Merge pull request #22662 from asgerf/unified/mad-approx
Unified: Port old MaD models from swift
2 parents a7db2a7 + 935956c commit ccaf910

17 files changed

Lines changed: 1802 additions & 20 deletions

File tree

‎unified/ql/lib/codeql/unified/internal/AnalysisQuality.qll‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,28 @@ module CallGraphStats implements EntityStatsSig {
108108
}
109109

110110
module CallGraphStatsReport = EntityReportStats<CallGraphStats>;
111+
112+
/**
113+
* Gets summary statistics about taint.
114+
*/
115+
predicate taintStats(string key, int value) {
116+
// The keys must match those in DCA summary profiles
117+
key = "Taint sources - active" and value = count(DataFlow::Node n | Models::isSource(n, "remote"))
118+
or
119+
key = "Taint sources - disabled" and
120+
value = count(DataFlow::Node n | Models::isSource(n, any(string s | s != "remote")))
121+
or
122+
key = "Taint sources - sensitive data" and none()
123+
or
124+
key = "Taint edges - number of edges" and none()
125+
or
126+
key = "Taint reach - nodes tainted" and none()
127+
or
128+
key = "Taint reach - total non-summary nodes" and none()
129+
or
130+
key = "Taint reach - per million nodes" and none()
131+
or
132+
key = "Taint sinks - query sinks" and value = count(DataFlow::Node n | Models::isSink(n, _))
133+
or
134+
key = "Taint sinks - cryptographic operations" and none()
135+
}

‎unified/ql/lib/codeql/unified/internal/FacadeAst.qll‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ overlay[local?]
55
module;
66

77
private import codeql.files.FileSystem
8+
private import codeql.unified.internal.NameBinding as NameBinding
89

910
module Unified {
1011
private import Ast::Unified as G
@@ -145,6 +146,13 @@ module Unified {
145146
class ClassLikeDeclaration extends G::ClassLikeDeclaration {
146147
/** Gets the name of this declaration. */
147148
string getName() { result = this.getNameNode().getValue() }
149+
150+
/** Gets a direct base class of this class. */
151+
ClassLikeDeclaration getABaseClass() {
152+
result.getNameNode() =
153+
NameBinding::getStaticBindingTarget(NameBinding::getIdentifierFromRef(this.getABaseType()
154+
.getType()))
155+
}
148156
}
149157

150158
class ConstructorDeclaration extends G::ConstructorDeclaration {
@@ -260,5 +268,10 @@ module Unified {
260268

261269
/** Gets the number of arguments passed to this call, not counting implicit arguments like receiver. */
262270
int getNumberOfArguments() { result = count(this.getAnArgument()) }
271+
272+
/** Gets the number of positional arguments passed to this call. */
273+
int getNumberOfPositionalArguments() {
274+
result = count(Argument arg | arg = this.getAnArgument() and arg.isPositional())
275+
}
263276
}
264277
}

‎unified/ql/lib/codeql/unified/internal/dataflow/DataFlowGraph.qll‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ module DebugGraph<relevantNodeSig/1 relevantNode> {
148148
if isUseStep = true then value = "use-use" else value = "def-use"
149149
)
150150
or
151-
node2 = getPostUpdateNode(node1) and
151+
node2 = node1.getPostUpdateNode() and
152152
value = "post-update"
153153
)
154154
}

‎unified/ql/lib/codeql/unified/internal/dataflow/DataFlowInstantiation.qll‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ module DataFlowInput implements InputSig<Location> {
101101
// Post-update nodes
102102
//
103103
class PostUpdateNode extends Node {
104-
PostUpdateNode() { this = getPostUpdateNode(_) }
104+
PostUpdateNode() { this = any(Node n).getPostUpdateNode() }
105105

106-
Node getPreUpdateNode() { this = getPostUpdateNode(result) }
106+
Node getPreUpdateNode() { this = result.getPostUpdateNode() }
107107
}
108108

109109
//

‎unified/ql/lib/codeql/unified/internal/dataflow/DataFlowNode.qll‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -315,21 +315,27 @@ class Node extends TDataFlowNode {
315315

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

320-
Node getPostUpdateNode(Node pre) {
321-
exists(Expr expr |
322-
pre.isResultValue(expr) and
323-
result.isPostUpdate(expr)
324-
)
325-
or
326-
exists(Expr expr, LocalVariable var |
327-
pre.isLocalVariableRead(expr, var) and
328-
result.isLocalVariablePostUpdate(expr, var)
329-
)
330-
or
331-
exists(DataFlowCall call |
332-
pre.isReceiverArgumentEx(call) and
333-
result.isReceiverPostUpdateEx(call)
334-
)
319+
/**
320+
* Gets the post-update node for this node, if any.
321+
*
322+
* 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.
323+
*/
324+
pragma[nomagic]
325+
Node getPostUpdateNode() {
326+
exists(Expr expr |
327+
this.isResultValue(expr) and
328+
result.isPostUpdate(expr)
329+
)
330+
or
331+
exists(Expr expr, LocalVariable var |
332+
this.isLocalVariableRead(expr, var) and
333+
result.isLocalVariablePostUpdate(expr, var)
334+
)
335+
or
336+
exists(DataFlowCall call |
337+
this.isReceiverArgumentEx(call) and
338+
result.isReceiverPostUpdateEx(call)
339+
)
340+
}
335341
}

‎unified/ql/lib/codeql/unified/internal/dataflow/LocalSsa.qll‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Node getNodeFromLocalSsaNode(Ssa::Node n) {
9595
result = n.(Ssa::ExprNode).getExpr() and
9696
not postUpdateReadNode(n)
9797
or
98-
result = getPostUpdateNode(n.(Ssa::ExprPostUpdateNode).getExpr())
98+
result = n.(Ssa::ExprPostUpdateNode).getExpr().(Node).getPostUpdateNode()
9999
or
100100
exists(LocalVariable v, BasicBlock bb, int i, AstNode repr |
101101
n.(Ssa::WriteDefSourceNode).getDefinition().definesAt(v, bb, i) and

0 commit comments

Comments
 (0)