mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Go: Adjust to FlowSummaryImpl changes.
This commit is contained in:
@@ -11,12 +11,7 @@ private newtype TNode =
|
||||
MkSsaNode(SsaDefinition ssa) or
|
||||
MkGlobalFunctionNode(Function f) or
|
||||
MkImplicitVarargsSlice(CallExpr c) { c.hasImplicitVarargs() } or
|
||||
MkSummarizedParameterNode(SummarizedCallable c, int i) {
|
||||
FlowSummaryImpl::Private::summaryParameterNodeRange(c, i)
|
||||
} or
|
||||
MkSummaryInternalNode(SummarizedCallable c, FlowSummaryImpl::Private::SummaryNodeState state) {
|
||||
FlowSummaryImpl::Private::summaryNodeRange(c, state)
|
||||
}
|
||||
MkFlowSummaryNode(FlowSummaryImpl::Private::SummaryNode sn)
|
||||
|
||||
/** Nodes intended for only use inside the data-flow libraries. */
|
||||
module Private {
|
||||
@@ -30,9 +25,7 @@ module Private {
|
||||
not exists(n.getEnclosingCallable()) and
|
||||
result.asFileScope() = n.getFile()
|
||||
or
|
||||
n = MkSummarizedParameterNode(result.asSummarizedCallable(), _)
|
||||
or
|
||||
n = MkSummaryInternalNode(result.asSummarizedCallable(), _)
|
||||
result.asSummarizedCallable() = n.(FlowSummaryNode).getSummarizedCallable()
|
||||
}
|
||||
|
||||
/** Holds if `p` is a `ParameterNode` of `c` with position `pos`. */
|
||||
@@ -52,7 +45,7 @@ module Private {
|
||||
ReturnNode() {
|
||||
this.(Public::ResultNode).getIndex() = kind.getIndex()
|
||||
or
|
||||
this.(SummaryNode).isReturn(kind)
|
||||
this.(FlowSummaryNode).isReturn(kind)
|
||||
}
|
||||
|
||||
/** Gets the kind of this returned value. */
|
||||
@@ -72,33 +65,33 @@ module Private {
|
||||
/**
|
||||
* A data-flow node used to model flow summaries.
|
||||
*/
|
||||
class SummaryNode extends Node, MkSummaryInternalNode {
|
||||
private SummarizedCallable c;
|
||||
private FlowSummaryImpl::Private::SummaryNodeState state;
|
||||
class FlowSummaryNode extends Node, MkFlowSummaryNode {
|
||||
FlowSummaryImpl::Private::SummaryNode getSummaryNode() { this = MkFlowSummaryNode(result) }
|
||||
|
||||
SummaryNode() { this = MkSummaryInternalNode(c, state) }
|
||||
|
||||
override predicate hasLocationInfo(string fp, int sl, int sc, int el, int ec) {
|
||||
c.hasLocationInfo(fp, sl, sc, el, ec)
|
||||
SummarizedCallable getSummarizedCallable() {
|
||||
result = this.getSummaryNode().getSummarizedCallable()
|
||||
}
|
||||
|
||||
override string toString() { result = "[summary] " + state + " in " + c }
|
||||
override predicate hasLocationInfo(string fp, int sl, int sc, int el, int ec) {
|
||||
this.getSummarizedCallable().hasLocationInfo(fp, sl, sc, el, ec)
|
||||
}
|
||||
|
||||
override string toString() { result = this.getSummaryNode().toString() }
|
||||
|
||||
/** Holds if this summary node is the `i`th argument of `call`. */
|
||||
predicate isArgumentOf(DataFlowCall call, int i) {
|
||||
FlowSummaryImpl::Private::summaryArgumentNode(call, this, i)
|
||||
FlowSummaryImpl::Private::summaryArgumentNode(call, this.getSummaryNode(), i)
|
||||
}
|
||||
|
||||
/** Holds if this summary node is a return node. */
|
||||
predicate isReturn(ReturnKind kind) { FlowSummaryImpl::Private::summaryReturnNode(this, kind) }
|
||||
predicate isReturn(ReturnKind kind) {
|
||||
FlowSummaryImpl::Private::summaryReturnNode(this.getSummaryNode(), kind)
|
||||
}
|
||||
|
||||
/** Holds if this summary node is an out node for `call`. */
|
||||
predicate isOut(DataFlowCall call) { FlowSummaryImpl::Private::summaryOutNode(call, this, _) }
|
||||
}
|
||||
|
||||
/** Gets the summary node corresponding to the callable `c` and state `state`. */
|
||||
SummaryNode getSummaryNode(SummarizedCallable c, FlowSummaryImpl::Private::SummaryNodeState state) {
|
||||
result = MkSummaryInternalNode(c, state)
|
||||
predicate isOut(DataFlowCall call) {
|
||||
FlowSummaryImpl::Private::summaryOutNode(call, this.getSummaryNode(), _)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,11 +654,14 @@ module Public {
|
||||
* A summary node which represents a parameter in a function which doesn't
|
||||
* already have a parameter nodes.
|
||||
*/
|
||||
class SummarizedParameterNode extends ParameterNode, MkSummarizedParameterNode {
|
||||
SummarizedCallable c;
|
||||
int i;
|
||||
class SummarizedParameterNode extends ParameterNode, FlowSummaryNode {
|
||||
SummarizedParameterNode() {
|
||||
FlowSummaryImpl::Private::summaryParameterNode(this.getSummaryNode(), _)
|
||||
}
|
||||
|
||||
SummarizedParameterNode() { this = MkSummarizedParameterNode(c, i) }
|
||||
private int getPos() {
|
||||
FlowSummaryImpl::Private::summaryParameterNode(this.getSummaryNode(), result)
|
||||
}
|
||||
|
||||
// There are no AST representations of summarized parameter nodes
|
||||
override ControlFlow::Root getRoot() { none() }
|
||||
@@ -673,19 +669,14 @@ module Public {
|
||||
override string getNodeKind() { result = "external parameter node" }
|
||||
|
||||
override Type getType() {
|
||||
result = c.getType().getParameterType(i)
|
||||
result = this.getSummarizedCallable().getType().getParameterType(this.getPos())
|
||||
or
|
||||
i = -1 and result = c.asFunction().(Method).getReceiverType()
|
||||
this.getPos() = -1 and
|
||||
result = this.getSummarizedCallable().asFunction().(Method).getReceiverType()
|
||||
}
|
||||
|
||||
override predicate isParameterOf(DataFlowCallable call, int idx) {
|
||||
c = call.asSummarizedCallable() and i = idx
|
||||
}
|
||||
|
||||
override string toString() { result = "parameter " + i + " of " + c.toString() }
|
||||
|
||||
override predicate hasLocationInfo(string fp, int sl, int sc, int el, int ec) {
|
||||
c.hasLocationInfo(fp, sl, sc, el, ec)
|
||||
this.getSummarizedCallable() = call.asSummarizedCallable() and this.getPos() = idx
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1237,10 +1228,12 @@ module Public {
|
||||
private import Private
|
||||
private import Public
|
||||
|
||||
class SummaryPostUpdateNode extends SummaryNode, PostUpdateNode {
|
||||
private Node pre;
|
||||
class SummaryPostUpdateNode extends FlowSummaryNode, PostUpdateNode {
|
||||
private FlowSummaryNode pre;
|
||||
|
||||
SummaryPostUpdateNode() { FlowSummaryImpl::Private::summaryPostUpdateNode(this, pre) }
|
||||
SummaryPostUpdateNode() {
|
||||
FlowSummaryImpl::Private::summaryPostUpdateNode(this.getSummaryNode(), pre.getSummaryNode())
|
||||
}
|
||||
|
||||
override Node getPreUpdateNode() { result = pre }
|
||||
}
|
||||
|
||||
@@ -129,7 +129,8 @@ predicate jumpStep(Node n1, Node n2) {
|
||||
n2 = recvRead
|
||||
)
|
||||
or
|
||||
FlowSummaryImpl::Private::Steps::summaryJumpStep(n1, n2)
|
||||
FlowSummaryImpl::Private::Steps::summaryJumpStep(n1.(FlowSummaryNode).getSummaryNode(),
|
||||
n2.(FlowSummaryNode).getSummaryNode())
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +154,8 @@ predicate storeStep(Node node1, Content c, Node node2) {
|
||||
node1 = node2.(AddressOperationNode).getOperand() and
|
||||
c = any(DataFlow::PointerContent pc | pc.getPointerType() = node2.getType())
|
||||
or
|
||||
FlowSummaryImpl::Private::Steps::summaryStoreStep(node1, c, node2)
|
||||
FlowSummaryImpl::Private::Steps::summaryStoreStep(node1.(FlowSummaryNode).getSummaryNode(), c,
|
||||
node2.(FlowSummaryNode).getSummaryNode())
|
||||
or
|
||||
containerStoreStep(node1, node2, c)
|
||||
}
|
||||
@@ -173,7 +175,8 @@ predicate readStep(Node node1, Content c, Node node2) {
|
||||
c = any(DataFlow::FieldContent fc | fc.getField() = read.getField())
|
||||
)
|
||||
or
|
||||
FlowSummaryImpl::Private::Steps::summaryReadStep(node1, c, node2)
|
||||
FlowSummaryImpl::Private::Steps::summaryReadStep(node1.(FlowSummaryNode).getSummaryNode(), c,
|
||||
node2.(FlowSummaryNode).getSummaryNode())
|
||||
or
|
||||
containerReadStep(node1, node2, c)
|
||||
}
|
||||
@@ -197,7 +200,7 @@ predicate clearsContent(Node n, Content c) {
|
||||
* at node `n`.
|
||||
*/
|
||||
predicate expectsContent(Node n, ContentSet c) {
|
||||
FlowSummaryImpl::Private::Steps::summaryExpectsContent(n, c)
|
||||
FlowSummaryImpl::Private::Steps::summaryExpectsContent(n.(FlowSummaryNode).getSummaryNode(), c)
|
||||
}
|
||||
|
||||
predicate typeStrongerThan(DataFlowType t1, DataFlowType t2) { none() }
|
||||
@@ -380,7 +383,7 @@ Node getArgument(CallNode c, int i) {
|
||||
}
|
||||
|
||||
/** Holds if `n` should be hidden from path explanations. */
|
||||
predicate nodeIsHidden(Node n) { n instanceof SummaryNode or n instanceof SummarizedParameterNode }
|
||||
predicate nodeIsHidden(Node n) { n instanceof FlowSummaryNode }
|
||||
|
||||
class LambdaCallKind = Unit;
|
||||
|
||||
|
||||
@@ -124,7 +124,8 @@ predicate simpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
|
||||
// step through function model
|
||||
any(FunctionModel m).flowStep(nodeFrom, nodeTo)
|
||||
or
|
||||
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom, nodeTo, true)
|
||||
FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom.(FlowSummaryNode).getSummaryNode(),
|
||||
nodeTo.(FlowSummaryNode).getSummaryNode(), true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,7 @@ private module FlowSummaries {
|
||||
|
||||
class SummarizedCallableBase = Callable;
|
||||
|
||||
DataFlowCallable inject(SummarizedCallable c) { result.asSummarizedCallable() = c }
|
||||
DataFlowCallable inject(SummarizedCallable c) { result.asSummarizedCallable() = c or none() }
|
||||
|
||||
/** Gets the parameter position of the instance parameter. */
|
||||
ArgumentPosition callbackSelfParameterPosition() { result = -1 }
|
||||
@@ -28,10 +28,8 @@ string getParameterPosition(ParameterPosition pos) { result = pos.toString() }
|
||||
/** Gets the textual representation of an argument position in the format used for flow summaries. */
|
||||
string getArgumentPosition(ArgumentPosition pos) { result = pos.toString() }
|
||||
|
||||
Node summaryNode(SummarizedCallable c, SummaryNodeState state) { result = getSummaryNode(c, state) }
|
||||
|
||||
/** Gets the synthesized data-flow call for `receiver`. */
|
||||
DataFlowCall summaryDataFlowCall(Node receiver) {
|
||||
DataFlowCall summaryDataFlowCall(SummaryNode receiver) {
|
||||
// We do not currently have support for callback-based library models.
|
||||
none()
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
private import go
|
||||
private import FlowSummaryImpl as FlowSummaryImpl
|
||||
private import codeql.util.Unit
|
||||
private import DataFlowPrivate as DataFlowPrivate
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
sliceStep(pred, succ) or
|
||||
any(FunctionModel fm).taintStep(pred, succ) or
|
||||
any(AdditionalTaintStep a).step(pred, succ) or
|
||||
FlowSummaryImpl::Private::Steps::summaryLocalStep(pred, succ, false)
|
||||
FlowSummaryImpl::Private::Steps::summaryLocalStep(pred.(DataFlowPrivate::FlowSummaryNode).getSummaryNode(),
|
||||
succ.(DataFlowPrivate::FlowSummaryNode).getSummaryNode(), false)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user