Skip to content

Commit e6e4cef

Browse files
committed
Go: Adjust to FlowSummaryImpl changes.
1 parent 5e60317 commit e6e4cef

File tree

5 files changed

+48
-51
lines changed

5 files changed

+48
-51
lines changed

go/ql/lib/semmle/go/dataflow/internal/DataFlowNodes.qll

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ private newtype TNode =
1111
MkSsaNode(SsaDefinition ssa) or
1212
MkGlobalFunctionNode(Function f) or
1313
MkImplicitVarargsSlice(CallExpr c) { c.hasImplicitVarargs() } or
14-
MkSummarizedParameterNode(SummarizedCallable c, int i) {
15-
FlowSummaryImpl::Private::summaryParameterNodeRange(c, i)
16-
} or
17-
MkSummaryInternalNode(SummarizedCallable c, FlowSummaryImpl::Private::SummaryNodeState state) {
18-
FlowSummaryImpl::Private::summaryNodeRange(c, state)
19-
}
14+
MkFlowSummaryNode(FlowSummaryImpl::Private::SummaryNode sn)
2015

2116
/** Nodes intended for only use inside the data-flow libraries. */
2217
module Private {
@@ -30,9 +25,7 @@ module Private {
3025
not exists(n.getEnclosingCallable()) and
3126
result.asFileScope() = n.getFile()
3227
or
33-
n = MkSummarizedParameterNode(result.asSummarizedCallable(), _)
34-
or
35-
n = MkSummaryInternalNode(result.asSummarizedCallable(), _)
28+
result.asSummarizedCallable() = n.(FlowSummaryNode).getSummarizedCallable()
3629
}
3730

3831
/** Holds if `p` is a `ParameterNode` of `c` with position `pos`. */
@@ -52,7 +45,7 @@ module Private {
5245
ReturnNode() {
5346
this.(Public::ResultNode).getIndex() = kind.getIndex()
5447
or
55-
this.(SummaryNode).isReturn(kind)
48+
this.(FlowSummaryNode).isReturn(kind)
5649
}
5750

5851
/** Gets the kind of this returned value. */
@@ -72,33 +65,33 @@ module Private {
7265
/**
7366
* A data-flow node used to model flow summaries.
7467
*/
75-
class SummaryNode extends Node, MkSummaryInternalNode {
76-
private SummarizedCallable c;
77-
private FlowSummaryImpl::Private::SummaryNodeState state;
68+
class FlowSummaryNode extends Node, MkFlowSummaryNode {
69+
FlowSummaryImpl::Private::SummaryNode getSummaryNode() { this = MkFlowSummaryNode(result) }
7870

79-
SummaryNode() { this = MkSummaryInternalNode(c, state) }
71+
SummarizedCallable getSummarizedCallable() {
72+
result = this.getSummaryNode().getSummarizedCallable()
73+
}
8074

8175
override predicate hasLocationInfo(string fp, int sl, int sc, int el, int ec) {
82-
c.hasLocationInfo(fp, sl, sc, el, ec)
76+
this.getSummarizedCallable().hasLocationInfo(fp, sl, sc, el, ec)
8377
}
8478

85-
override string toString() { result = "[summary] " + state + " in " + c }
79+
override string toString() { result = this.getSummaryNode().toString() }
8680

8781
/** Holds if this summary node is the `i`th argument of `call`. */
8882
predicate isArgumentOf(DataFlowCall call, int i) {
89-
FlowSummaryImpl::Private::summaryArgumentNode(call, this, i)
83+
FlowSummaryImpl::Private::summaryArgumentNode(call, this.getSummaryNode(), i)
9084
}
9185

9286
/** Holds if this summary node is a return node. */
93-
predicate isReturn(ReturnKind kind) { FlowSummaryImpl::Private::summaryReturnNode(this, kind) }
87+
predicate isReturn(ReturnKind kind) {
88+
FlowSummaryImpl::Private::summaryReturnNode(this.getSummaryNode(), kind)
89+
}
9490

9591
/** Holds if this summary node is an out node for `call`. */
96-
predicate isOut(DataFlowCall call) { FlowSummaryImpl::Private::summaryOutNode(call, this, _) }
97-
}
98-
99-
/** Gets the summary node corresponding to the callable `c` and state `state`. */
100-
SummaryNode getSummaryNode(SummarizedCallable c, FlowSummaryImpl::Private::SummaryNodeState state) {
101-
result = MkSummaryInternalNode(c, state)
92+
predicate isOut(DataFlowCall call) {
93+
FlowSummaryImpl::Private::summaryOutNode(call, this.getSummaryNode(), _)
94+
}
10295
}
10396
}
10497

@@ -661,31 +654,29 @@ module Public {
661654
* A summary node which represents a parameter in a function which doesn't
662655
* already have a parameter nodes.
663656
*/
664-
class SummarizedParameterNode extends ParameterNode, MkSummarizedParameterNode {
665-
SummarizedCallable c;
666-
int i;
657+
class SummarizedParameterNode extends ParameterNode, FlowSummaryNode {
658+
SummarizedParameterNode() {
659+
FlowSummaryImpl::Private::summaryParameterNode(this.getSummaryNode(), _)
660+
}
667661

668-
SummarizedParameterNode() { this = MkSummarizedParameterNode(c, i) }
662+
private int getPos() {
663+
FlowSummaryImpl::Private::summaryParameterNode(this.getSummaryNode(), result)
664+
}
669665

670666
// There are no AST representations of summarized parameter nodes
671667
override ControlFlow::Root getRoot() { none() }
672668

673669
override string getNodeKind() { result = "external parameter node" }
674670

675671
override Type getType() {
676-
result = c.getType().getParameterType(i)
672+
result = this.getSummarizedCallable().getType().getParameterType(this.getPos())
677673
or
678-
i = -1 and result = c.asFunction().(Method).getReceiverType()
674+
this.getPos() = -1 and
675+
result = this.getSummarizedCallable().asFunction().(Method).getReceiverType()
679676
}
680677

681678
override predicate isParameterOf(DataFlowCallable call, int idx) {
682-
c = call.asSummarizedCallable() and i = idx
683-
}
684-
685-
override string toString() { result = "parameter " + i + " of " + c.toString() }
686-
687-
override predicate hasLocationInfo(string fp, int sl, int sc, int el, int ec) {
688-
c.hasLocationInfo(fp, sl, sc, el, ec)
679+
this.getSummarizedCallable() = call.asSummarizedCallable() and this.getPos() = idx
689680
}
690681
}
691682

@@ -1237,10 +1228,12 @@ module Public {
12371228
private import Private
12381229
private import Public
12391230

1240-
class SummaryPostUpdateNode extends SummaryNode, PostUpdateNode {
1241-
private Node pre;
1231+
class SummaryPostUpdateNode extends FlowSummaryNode, PostUpdateNode {
1232+
private FlowSummaryNode pre;
12421233

1243-
SummaryPostUpdateNode() { FlowSummaryImpl::Private::summaryPostUpdateNode(this, pre) }
1234+
SummaryPostUpdateNode() {
1235+
FlowSummaryImpl::Private::summaryPostUpdateNode(this.getSummaryNode(), pre.getSummaryNode())
1236+
}
12441237

12451238
override Node getPreUpdateNode() { result = pre }
12461239
}

go/ql/lib/semmle/go/dataflow/internal/DataFlowPrivate.qll

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ predicate jumpStep(Node n1, Node n2) {
129129
n2 = recvRead
130130
)
131131
or
132-
FlowSummaryImpl::Private::Steps::summaryJumpStep(n1, n2)
132+
FlowSummaryImpl::Private::Steps::summaryJumpStep(n1.(FlowSummaryNode).getSummaryNode(),
133+
n2.(FlowSummaryNode).getSummaryNode())
133134
}
134135

135136
/**
@@ -153,7 +154,8 @@ predicate storeStep(Node node1, Content c, Node node2) {
153154
node1 = node2.(AddressOperationNode).getOperand() and
154155
c = any(DataFlow::PointerContent pc | pc.getPointerType() = node2.getType())
155156
or
156-
FlowSummaryImpl::Private::Steps::summaryStoreStep(node1, c, node2)
157+
FlowSummaryImpl::Private::Steps::summaryStoreStep(node1.(FlowSummaryNode).getSummaryNode(), c,
158+
node2.(FlowSummaryNode).getSummaryNode())
157159
or
158160
containerStoreStep(node1, node2, c)
159161
}
@@ -173,7 +175,8 @@ predicate readStep(Node node1, Content c, Node node2) {
173175
c = any(DataFlow::FieldContent fc | fc.getField() = read.getField())
174176
)
175177
or
176-
FlowSummaryImpl::Private::Steps::summaryReadStep(node1, c, node2)
178+
FlowSummaryImpl::Private::Steps::summaryReadStep(node1.(FlowSummaryNode).getSummaryNode(), c,
179+
node2.(FlowSummaryNode).getSummaryNode())
177180
or
178181
containerReadStep(node1, node2, c)
179182
}
@@ -197,7 +200,7 @@ predicate clearsContent(Node n, Content c) {
197200
* at node `n`.
198201
*/
199202
predicate expectsContent(Node n, ContentSet c) {
200-
FlowSummaryImpl::Private::Steps::summaryExpectsContent(n, c)
203+
FlowSummaryImpl::Private::Steps::summaryExpectsContent(n.(FlowSummaryNode).getSummaryNode(), c)
201204
}
202205

203206
predicate typeStrongerThan(DataFlowType t1, DataFlowType t2) { none() }
@@ -380,7 +383,7 @@ Node getArgument(CallNode c, int i) {
380383
}
381384

382385
/** Holds if `n` should be hidden from path explanations. */
383-
predicate nodeIsHidden(Node n) { n instanceof SummaryNode or n instanceof SummarizedParameterNode }
386+
predicate nodeIsHidden(Node n) { n instanceof FlowSummaryNode }
384387

385388
class LambdaCallKind = Unit;
386389

go/ql/lib/semmle/go/dataflow/internal/DataFlowUtil.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ predicate simpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
124124
// step through function model
125125
any(FunctionModel m).flowStep(nodeFrom, nodeTo)
126126
or
127-
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom, nodeTo, true)
127+
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom.(FlowSummaryNode).getSummaryNode(),
128+
nodeTo.(FlowSummaryNode).getSummaryNode(), true)
128129
}
129130

130131
/**

go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImplSpecific.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private module FlowSummaries {
1717

1818
class SummarizedCallableBase = Callable;
1919

20-
DataFlowCallable inject(SummarizedCallable c) { result.asSummarizedCallable() = c }
20+
DataFlowCallable inject(SummarizedCallable c) { result.asSummarizedCallable() = c or none() }
2121

2222
/** Gets the parameter position of the instance parameter. */
2323
ArgumentPosition callbackSelfParameterPosition() { result = -1 }
@@ -28,10 +28,8 @@ string getParameterPosition(ParameterPosition pos) { result = pos.toString() }
2828
/** Gets the textual representation of an argument position in the format used for flow summaries. */
2929
string getArgumentPosition(ArgumentPosition pos) { result = pos.toString() }
3030

31-
Node summaryNode(SummarizedCallable c, SummaryNodeState state) { result = getSummaryNode(c, state) }
32-
3331
/** Gets the synthesized data-flow call for `receiver`. */
34-
DataFlowCall summaryDataFlowCall(Node receiver) {
32+
DataFlowCall summaryDataFlowCall(SummaryNode receiver) {
3533
// We do not currently have support for callback-based library models.
3634
none()
3735
}

go/ql/lib/semmle/go/dataflow/internal/TaintTrackingUtil.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
private import go
66
private import FlowSummaryImpl as FlowSummaryImpl
77
private import codeql.util.Unit
8+
private import DataFlowPrivate as DataFlowPrivate
89

910
/**
1011
* Holds if taint can flow from `src` to `sink` in zero or more
@@ -95,7 +96,8 @@ predicate localAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
9596
sliceStep(pred, succ) or
9697
any(FunctionModel fm).taintStep(pred, succ) or
9798
any(AdditionalTaintStep a).step(pred, succ) or
98-
FlowSummaryImpl::Private::Steps::summaryLocalStep(pred, succ, false)
99+
FlowSummaryImpl::Private::Steps::summaryLocalStep(pred.(DataFlowPrivate::FlowSummaryNode).getSummaryNode(),
100+
succ.(DataFlowPrivate::FlowSummaryNode).getSummaryNode(), false)
99101
}
100102

101103
/**

0 commit comments

Comments
 (0)