Skip to content

Commit

Permalink
Address more review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hvitved committed Dec 14, 2023
1 parent a46964d commit 098afb9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ private predicate interpretSummary(
)
}

// adapter class for converting Mad summaries to `SummarizedCallable`s
private class SummarizedCallableAdapter extends SummarizedCallable {
SummarizedCallableAdapter() { interpretSummary(this, _, _, _, _) }

Expand Down Expand Up @@ -549,6 +550,7 @@ private class SummarizedCallableAdapter extends SummarizedCallable {
}
}

// adapter class for converting Mad neutrals to `NeutralCallable`s
private class NeutralCallableAdapter extends NeutralCallable {
string kind;
string provenance_;
Expand Down
2 changes: 2 additions & 0 deletions go/ql/lib/semmle/go/dataflow/ExternalFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ private predicate interpretSummary(
)
}

// adapter class for converting Mad summaries to `SummarizedCallable`s
private class SummarizedCallableAdapter extends SummarizedCallable {
SummarizedCallableAdapter() { interpretSummary(this, _, _, _, _) }

Expand Down Expand Up @@ -417,6 +418,7 @@ private class SummarizedCallableAdapter extends SummarizedCallable {
}
}

// adapter class for converting Mad neutrals to `NeutralCallable`s
private class NeutralCallableAdapter extends NeutralCallable {
string kind;
string provenance_;
Expand Down
2 changes: 2 additions & 0 deletions java/ql/lib/semmle/code/java/dataflow/ExternalFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ private module Cached {

import Cached

// adapter class for converting Mad summaries to `SummarizedCallable`s
private class SummarizedCallableAdapter extends SummarizedCallable {
SummarizedCallableAdapter() { summaryElement(this, _, _, _, _) }

Expand Down Expand Up @@ -546,6 +547,7 @@ private class SummarizedCallableAdapter extends SummarizedCallable {
}
}

// adapter class for converting Mad neutrals to `NeutralCallable`s
private class NeutralCallableAdapter extends NeutralCallable {
string kind;
string provenance_;
Expand Down
4 changes: 2 additions & 2 deletions shared/dataflow/codeql/dataflow/internal/AccessPathSyntax.qll
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bindingset[arg]
int parseLowerBound(string arg) { result = arg.regexpCapture("(-?\\d+)\\.\\.", 1).toInt() }

/**
* An access part token such as `Argument[1]` or `ReturnValue`.
* An access path token such as `Argument[1]` or `ReturnValue`.
*/
class AccessPathTokenBase extends string {
bindingset[this]
Expand Down Expand Up @@ -181,7 +181,7 @@ module AccessPath<accessPathRangeSig/1 accessPathRange> {
}

/**
* An access part token such as `Argument[1]` or `ReturnValue`, appearing in one or more access paths.
* An access path token such as `Argument[1]` or `ReturnValue`, appearing in one or more access paths.
*/
class AccessPathToken extends AccessPathTokenBaseFinal {
AccessPathToken() { this = getRawToken(_, _) }
Expand Down
50 changes: 12 additions & 38 deletions shared/dataflow/codeql/dataflow/internal/FlowSummaryImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -394,16 +394,12 @@ module Make<DF::InputSig DataFlowLang, InputSig<DataFlowLang> Input> {
}
}

private predicate summaryElement(
SummarizedCallable c, string input, string output, boolean preservesValue, string provenance
) {
c.propagatesFlow(input, output, preservesValue) and
c.hasProvenance(provenance)
}

private predicate summarySpec(string spec) {
summaryElement(_, spec, _, _, _) or
summaryElement(_, _, spec, _, _)
exists(SummarizedCallable c |
c.propagatesFlow(spec, _, _)
or
c.propagatesFlow(_, spec, _)
)
}

import AccessPathSyntax::AccessPath<summarySpec/1>
Expand Down Expand Up @@ -652,7 +648,7 @@ module Make<DF::InputSig DataFlowLang, InputSig<DataFlowLang> Input> {

/**
* Holds if `c` has a flow summary from `input` to `arg`, where `arg`
* writes to (contents of) arguments at position `pos`, and `c` has a
* writes to (contents of) arguments at (some) position `pos`, and `c` has a
* value-preserving flow summary from the arguments at position `pos`
* to a return value (`return`).
*
Expand Down Expand Up @@ -1423,43 +1419,21 @@ module Make<DF::InputSig DataFlowLang, InputSig<DataFlowLang> Input> {
}
}

private class SummarizedCallableExternal extends SummarizedCallableImpl instanceof SummarizedCallable
// adapter class for converting `SummarizedCallable`s to `SummarizedCallableImpl`s
private class SummarizedCallableImplAdapter extends SummarizedCallableImpl instanceof SummarizedCallable
{
SummarizedCallableExternal() { summaryElement(this, _, _, _, _) }

private predicate relevantSummaryElementGenerated(
AccessPath inSpec, AccessPath outSpec, boolean preservesValue
) {
exists(Provenance provenance |
provenance.isGenerated() and
summaryElement(this, inSpec, outSpec, preservesValue, provenance)
) and
not super.applyManualModel()
}

private predicate relevantSummaryElement(
AccessPath inSpec, AccessPath outSpec, boolean preservesValue
) {
exists(Provenance provenance |
provenance.isManual() and
summaryElement(this, inSpec, outSpec, preservesValue, provenance)
)
or
this.relevantSummaryElementGenerated(inSpec, outSpec, preservesValue)
}

override predicate propagatesFlow(
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue
) {
exists(AccessPath inSpec, AccessPath outSpec |
this.relevantSummaryElement(inSpec, outSpec, preservesValue) and
SummarizedCallable.super.propagatesFlow(inSpec, outSpec, preservesValue) and
interpretSpec(inSpec, input) and
interpretSpec(outSpec, output)
)
}

override predicate hasProvenance(Provenance provenance) {
summaryElement(this, _, _, _, provenance)
SummarizedCallable.super.hasProvenance(provenance)
}
}

Expand Down Expand Up @@ -1492,13 +1466,13 @@ module Make<DF::InputSig DataFlowLang, InputSig<DataFlowLang> Input> {

/**
* Holds if an external source specification exists for `n` with output specification
* `output`, kind `kind`, and provenance `provenance`.
* `output` and kind `kind`.
*/
predicate sourceElement(Element n, string output, string kind);

/**
* Holds if an external sink specification exists for `n` with input specification
* `input`, kind `kind` and provenance `provenance`.
* `input` and kind `kind`.
*/
predicate sinkElement(Element n, string input, string kind);

Expand Down
2 changes: 2 additions & 0 deletions swift/ql/lib/codeql/swift/dataflow/ExternalFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ private predicate interpretSummary(
)
}

// adapter class for converting Mad summaries to `SummarizedCallable`s
private class SummarizedCallableAdapter extends SummarizedCallable {
SummarizedCallableAdapter() { interpretSummary(this, _, _, _, _) }

Expand Down Expand Up @@ -560,6 +561,7 @@ private class SummarizedCallableAdapter extends SummarizedCallable {
}
}

// adapter class for converting Mad neutrals to `NeutralCallable`s
private class NeutralCallableAdapter extends NeutralCallable {
string kind;
string provenance_;
Expand Down

0 comments on commit 098afb9

Please sign in to comment.