Skip to content
Draft
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
52 changes: 40 additions & 12 deletions cpp/ql/lib/semmle/code/cpp/dataflow/internal/FlowSummaryImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ module Input implements InputSig<Location, DataFlowImplSpecific::CppDataFlow> {

class SummarizedCallableBase = Function;

class SourceBase = Void;
class SourceBase extends Void {
Location getLocation() { none() }
}

class SinkBase = Void;
class SinkBase = SourceBase;

class FlowSummaryCallBase = CallInstruction;

Expand Down Expand Up @@ -132,11 +134,42 @@ module Input implements InputSig<Location, DataFlowImplSpecific::CppDataFlow> {

private import Make<Location, DataFlowImplSpecific::CppDataFlow, Input> as Impl

private module StepsInput implements Impl::Private::StepsInputSig {
Impl::Private::SummaryNode getSummaryNode(Node n) {
result = n.(FlowSummaryNode).getSummaryNode()
private module Input2 implements Impl::Private::InputSig2 {
private import codeql.util.Void

class SourceSinkReportingElement extends Void {
Location getLocation() { none() }

DataFlowCallable getEnclosingCallable() { none() }
}

bindingset[source, s]
SourceSinkReportingElement getSourceEntryElement(
Impl::Public::SourceElement source, Impl::Private::SummaryComponentStack s
) {
none()
}

bindingset[e, s]
Node getSourceExitNode(SourceSinkReportingElement e, Impl::Private::SummaryComponentStack s) {
none()
}

SourceSinkReportingElement getSinkExitElement(
Impl::Public::SinkElement sink, Impl::Private::SummaryComponent sc
) {
none()
}

bindingset[e, sc]
Node getSinkEntryNode(SourceSinkReportingElement e, Impl::Private::SummaryComponent sc) { none() }
}

private import Impl::Private::Make2<Input2> as Impl2

private module StepsInput implements Impl2::StepsInputSig {
Impl2::SummaryNode getSummaryNode(Node n) { result = n.(FlowSummaryNode).getSummaryNode() }

DataFlowCall getACall(Public::SummarizedCallable sc) {
result.getStaticCallTarget().getUnderlyingCallable() = sc
}
Expand All @@ -148,12 +181,6 @@ private module StepsInput implements Impl::Private::StepsInputSig {
pragma[only_bind_out](out.getIndirectionIndex())
)
}

DataFlowCallable getSourceNodeEnclosingCallable(Input::SourceBase source) { none() }

Node getSourceNode(Input::SourceBase source, Impl::Private::SummaryComponentStack s) { none() }

Node getSinkNode(Input::SinkBase sink, Impl::Private::SummaryComponent sc) { none() }
}

module SourceSinkInterpretationInput implements
Expand Down Expand Up @@ -270,8 +297,9 @@ module SourceSinkInterpretationInput implements

module Private {
import Impl::Private
import Impl2

module Steps = Impl::Private::Steps<StepsInput>;
module Steps = Impl2::Steps<StepsInput>;

module External {
import Impl::Private::External
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1535,10 +1535,10 @@ class FlowSummaryNode extends Node, TFlowSummaryNode {
}

override DataFlowCallable getEnclosingCallable() {
result = FlowSummaryImpl::Private::getEnclosingCallable(this.getSummaryNode())
result = this.getSummaryNode().getEnclosingCallable()
}

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

override string toStringImpl() { result = this.getSummaryNode().toString() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ class FlowSummaryNode extends NodeImpl, TFlowSummaryNode {
}

override DataFlowCallable getEnclosingCallableImpl() {
result.asSummarizedCallable() = this.getSummarizedCallable()
result = this.getSummaryNode().getEnclosingCallable()
}

override DataFlowType getDataFlowType() {
Expand All @@ -1789,7 +1789,7 @@ class FlowSummaryNode extends NodeImpl, TFlowSummaryNode {

override ControlFlowNode getControlFlowNodeImpl() { none() }

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

override string toStringImpl() { result = this.getSummaryNode().toString() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ module Input implements InputSig<Location, DataFlowImplSpecific::CsharpDataFlow>
)
}

class SourceBase = Void;
class SourceBase extends Void {
Location getLocation() { none() }
}

class SinkBase = SourceBase;

class SinkBase = Void;
class FlowSummaryCallBase = SourceBase;

class FlowSummaryCallBase = Void;
DataFlowCallable getSummarizedCallableAsDataFlowCallable(SummarizedCallableBase c) {
result.asSummarizedCallable() = c
}

predicate neutralElement(SummarizedCallableBase c, string kind, string provenance, boolean isExact) {
interpretNeutral(c, kind, provenance, isExact)
Expand Down Expand Up @@ -122,7 +128,40 @@ module Input implements InputSig<Location, DataFlowImplSpecific::CsharpDataFlow>

private import Make<Location, DataFlowImplSpecific::CsharpDataFlow, Input> as Impl

private module TypesInput implements Impl::Private::TypesInputSig {
private module Input2 implements Impl::Private::InputSig2 {
private import codeql.util.Void

class SourceSinkReportingElement extends Void {
Location getLocation() { none() }

DataFlowCallable getEnclosingCallable() { none() }
}

bindingset[source, s]
SourceSinkReportingElement getSourceEntryElement(
Impl::Public::SourceElement source, Impl::Private::SummaryComponentStack s
) {
none()
}

bindingset[e, s]
Node getSourceExitNode(SourceSinkReportingElement e, Impl::Private::SummaryComponentStack s) {
none()
}

SourceSinkReportingElement getSinkExitElement(
Impl::Public::SinkElement sink, Impl::Private::SummaryComponent sc
) {
none()
}

bindingset[e, sc]
Node getSinkEntryNode(SourceSinkReportingElement e, Impl::Private::SummaryComponent sc) { none() }
}

private import Impl::Private::Make2<Input2> as Impl2

private module TypesInput implements Impl2::TypesInputSig {
DataFlowType getSyntheticGlobalType(Impl::Private::SyntheticGlobal sg) {
exists(sg) and
result.asGvnType() = Gvn::getGlobalValueNumber(any(ObjectType t))
Expand Down Expand Up @@ -202,20 +241,12 @@ private module TypesInput implements Impl::Private::TypesInputSig {
DataFlowType getSinkType(Input::SinkBase sink, Impl::Private::SummaryComponent sc) { none() }
}

private module StepsInput implements Impl::Private::StepsInputSig {
Impl::Private::SummaryNode getSummaryNode(Node n) {
result = n.(FlowSummaryNode).getSummaryNode()
}
private module StepsInput implements Impl2::StepsInputSig {
Impl2::SummaryNode getSummaryNode(Node n) { result = n.(FlowSummaryNode).getSummaryNode() }

DataFlowCall getACall(Public::SummarizedCallable sc) {
sc = viableCallable(result).asSummarizedCallable()
}

DataFlowCallable getSourceNodeEnclosingCallable(Input::SourceBase source) { none() }

Node getSourceNode(Input::SourceBase source, Impl::Private::SummaryComponentStack s) { none() }

Node getSinkNode(Input::SinkBase sink, Impl::Private::SummaryComponent sc) { none() }
}

module SourceSinkInterpretationInput implements
Expand Down Expand Up @@ -339,9 +370,10 @@ module SourceSinkInterpretationInput implements

module Private {
import Impl::Private
import Impl::Private::Types<TypesInput>
import Impl2
import Types<TypesInput>

module Steps = Impl::Private::Steps<StepsInput>;
module Steps = Impl2::Steps<StepsInput>;

module External {
import Impl::Private::External
Expand Down
2 changes: 1 addition & 1 deletion go/ql/lib/semmle/go/dataflow/internal/DataFlowNodes.qll
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module Private {
result = this.getSummaryNode().getSummarizedCallable()
}

override Location getLocation() { result = this.getSummarizedCallable().getLocation() }
override Location getLocation() { result = this.getSummaryNode().getLocation() }

override string toString() { result = this.getSummaryNode().toString() }

Expand Down
58 changes: 45 additions & 13 deletions go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,20 @@ module Input implements InputSig<Location, DataFlowImplSpecific::GoDataFlow> {

class SummarizedCallableBase = Callable;

class SourceBase = Void;
class SourceBase extends Void {
Location getLocation() { none() }
}

class SinkBase = Void;
class SinkBase = SourceBase;

class FlowSummaryCallBase = Void;
class FlowSummaryCallBase = SourceBase;

predicate callableFromSource(SummarizedCallableBase c) { exists(c.getFuncDef()) }

DataFlowCallable getSummarizedCallableAsDataFlowCallable(SummarizedCallableBase c) {
result.asSummarizedCallable() = c
}

predicate neutralElement(
Input::SummarizedCallableBase c, string kind, string provenance, boolean isExact
) {
Expand Down Expand Up @@ -114,23 +120,48 @@ module Input implements InputSig<Location, DataFlowImplSpecific::GoDataFlow> {

private import Make<Location, DataFlowImplSpecific::GoDataFlow, Input> as Impl

private module StepsInput implements Impl::Private::StepsInputSig {
Impl::Private::SummaryNode getSummaryNode(Node n) {
result = n.(FlowSummaryNode).getSummaryNode()
private module Input2 implements Impl::Private::InputSig2 {
private import codeql.util.Void

class SourceSinkReportingElement extends Void {
Location getLocation() { none() }

DataFlowCallable getEnclosingCallable() { none() }
}

bindingset[source, s]
SourceSinkReportingElement getSourceEntryElement(
Impl::Public::SourceElement source, Impl::Private::SummaryComponentStack s
) {
none()
}

bindingset[e, s]
Node getSourceExitNode(SourceSinkReportingElement e, Impl::Private::SummaryComponentStack s) {
none()
}

SourceSinkReportingElement getSinkExitElement(
Impl::Public::SinkElement sink, Impl::Private::SummaryComponent sc
) {
none()
}

bindingset[e, sc]
Node getSinkEntryNode(SourceSinkReportingElement e, Impl::Private::SummaryComponent sc) { none() }
}

private import Impl::Private::Make2<Input2> as Impl2

private module StepsInput implements Impl2::StepsInputSig {
Impl2::SummaryNode getSummaryNode(Node n) { result = n.(FlowSummaryNode).getSummaryNode() }

DataFlowCall getACall(Public::SummarizedCallable sc) {
exists(DataFlow::CallNode call |
call.asExpr() = result and
call.getACalleeIncludingExternals() = sc
)
}

DataFlowCallable getSourceNodeEnclosingCallable(Input::SourceBase source) { none() }

Node getSourceNode(Input::SourceBase source, Impl::Private::SummaryComponentStack s) { none() }

Node getSinkNode(Input::SinkBase sink, Impl::Private::SummaryComponent sc) { none() }
}

module SourceSinkInterpretationInput implements
Expand Down Expand Up @@ -500,8 +531,9 @@ private predicate parseReturn(AccessPath::AccessPathTokenBase c, int n) {

module Private {
import Impl::Private
import Impl2

module Steps = Impl::Private::Steps<StepsInput>;
module Steps = Impl2::Steps<StepsInput>;

module External {
import Impl::Private::External
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ module Private {
result.asCallable() = n.(ImplicitInstanceAccess).getInstanceAccess().getEnclosingCallable() or
result.asCallable() = n.(MallocNode).getClassInstanceExpr().getEnclosingCallable() or
result = nodeGetEnclosingCallable(n.(ImplicitPostUpdateNode).getPreUpdateNode()) or
result.asSummarizedCallable() = n.(FlowSummaryNode).getSummarizedCallable() or
result = n.(FlowSummaryNode).getSummaryNode().getEnclosingCallable() or
result.asCallable() = n.(CaptureNode).getSynthesizedCaptureNode().getEnclosingCallable() or
result.asFieldScope() = n.(FieldValueNode).getField() or
result.asCallable() = any(Expr e | n.(AdditionalNode).nodeAt(e, _)).getEnclosingCallable() or
Expand Down Expand Up @@ -531,7 +531,7 @@ module Private {
result = this.getSummaryNode().getSummarizedCallable()
}

override Location getLocation() { result = this.getSummarizedCallable().getLocation() }
override Location getLocation() { result = this.getSummaryNode().getLocation() }

override string toString() { result = this.getSummaryNode().toString() }

Expand Down
Loading
Loading