Skip to content

Commit b974a84

Browse files
authored
Merge pull request #21051 from hvitved/shared/flow-summary-provenance-filtering
Shared: Provenance-based filtering of flow summaries
2 parents 2bd4cce + df09f02 commit b974a84

File tree

142 files changed

+15876
-21185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+15876
-21185
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The predicate `SummarizedCallable.propagatesFlow` has been extended with the columns `Provenance p` and `boolean isExact`, and as a consequence the predicates `SummarizedCallable.hasProvenance` and `SummarizedCallable.hasExactModel` have been removed.

cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,40 +1145,22 @@ private predicate interpretSummary(
11451145

11461146
// adapter class for converting Mad summaries to `SummarizedCallable`s
11471147
private class SummarizedCallableAdapter extends SummarizedCallable {
1148-
SummarizedCallableAdapter() { interpretSummary(this, _, _, _, _, _) }
1148+
string input_;
1149+
string output_;
1150+
string kind;
1151+
Provenance p_;
1152+
string model_;
11491153

1150-
private predicate relevantSummaryElementManual(
1151-
string input, string output, string kind, string model
1152-
) {
1153-
exists(Provenance provenance |
1154-
interpretSummary(this, input, output, kind, provenance, model) and
1155-
provenance.isManual()
1156-
)
1157-
}
1158-
1159-
private predicate relevantSummaryElementGenerated(
1160-
string input, string output, string kind, string model
1161-
) {
1162-
exists(Provenance provenance |
1163-
interpretSummary(this, input, output, kind, provenance, model) and
1164-
provenance.isGenerated()
1165-
)
1166-
}
1154+
SummarizedCallableAdapter() { interpretSummary(this, input_, output_, kind, p_, model_) }
11671155

11681156
override predicate propagatesFlow(
1169-
string input, string output, boolean preservesValue, string model
1157+
string input, string output, boolean preservesValue, Provenance p, boolean isExact, string model
11701158
) {
1171-
exists(string kind |
1172-
this.relevantSummaryElementManual(input, output, kind, model)
1173-
or
1174-
not this.relevantSummaryElementManual(_, _, _, _) and
1175-
this.relevantSummaryElementGenerated(input, output, kind, model)
1176-
|
1177-
if kind = "value" then preservesValue = true else preservesValue = false
1178-
)
1179-
}
1180-
1181-
override predicate hasProvenance(Provenance provenance) {
1182-
interpretSummary(this, _, _, _, provenance, _)
1159+
input = input_ and
1160+
output = output_ and
1161+
(if kind = "value" then preservesValue = true else preservesValue = false) and
1162+
p = p_ and
1163+
isExact = true and
1164+
model = model_
11831165
}
11841166
}

cpp/ql/lib/semmle/code/cpp/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ module Input implements InputSig<Location, DataFlowImplSpecific::CppDataFlow> {
2020

2121
class SinkBase = Void;
2222

23+
predicate callableFromSource(SummarizedCallableBase c) { exists(c.getBlock()) }
24+
2325
ArgumentPosition callbackSelfParameterPosition() { result = TDirectPosition(-1) }
2426

2527
ReturnKind getStandardReturnValueKind() { result = getReturnValueKind("") }

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ private newtype TDataFlowCall =
11441144
}
11451145

11461146
private predicate summarizedCallableIsManual(SummarizedCallable sc) {
1147-
sc.asSummarizedCallable().applyManualModel()
1147+
sc.asSummarizedCallable().hasManualModel()
11481148
}
11491149

11501150
/**

cpp/ql/src/utils/modelgenerator/internal/CaptureModels.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ private module SummaryModelGeneratorInput implements SummaryModelGeneratorInputS
310310
}
311311

312312
private predicate hasManualSummaryModel(Callable api) {
313-
api = any(FlowSummaryImpl::Public::SummarizedCallable sc | sc.applyManualModel()) or
313+
api = any(FlowSummaryImpl::Public::SummarizedCallable sc | sc.hasManualModel()) or
314314
api = any(FlowSummaryImpl::Public::NeutralSummaryCallable sc | sc.hasManualModel())
315315
}
316316

cpp/ql/test/library-tests/dataflow/external-models/steps.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@
33
| test.cpp:21:27:21:27 | x | test.cpp:21:10:21:25 | call to ymlStepGenerated |
44
| test.cpp:25:35:25:35 | x | test.cpp:25:11:25:33 | call to ymlStepManual_with_body |
55
| test.cpp:28:35:28:35 | 0 | test.cpp:28:11:28:33 | call to ymlStepManual_with_body |
6-
| test.cpp:32:38:32:38 | 0 | test.cpp:32:11:32:36 | call to ymlStepGenerated_with_body |
7-
| test.cpp:35:38:35:38 | x | test.cpp:35:11:35:36 | call to ymlStepGenerated_with_body |
86
| windows.cpp:27:36:27:38 | *cmd | windows.cpp:27:17:27:34 | **call to CommandLineToArgvA |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The predicate `SummarizedCallable.propagatesFlow` has been extended with the columns `Provenance p` and `boolean isExact`, and as a consequence the predicates `SummarizedCallable.hasProvenance` and `SummarizedCallable.hasExactModel` have been removed.

csharp/ql/lib/semmle/code/csharp/dataflow/FlowSummary.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ deprecated module SummaryComponentStack = Impl::Private::SummaryComponentStack;
1818

1919
deprecated class RequiredSummaryComponentStack = Impl::Private::RequiredSummaryComponentStack;
2020

21-
class SummarizedCallable = Impl::Public::SummarizedCallable;
21+
/** Provides the `Range` class used to define the extent of `SummarizedCallable`. */
22+
module SummarizedCallable {
23+
class Range = Impl::Public::SummarizedCallable;
24+
}
25+
26+
class SummarizedCallable = Impl::Public::RelevantSummarizedCallable;
2227

2328
class Provenance = Impl::Public::Provenance;

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowDispatch.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,7 @@ class NonDelegateDataFlowCall extends DataFlowCall, TNonDelegateCall {
380380
// we are not able to dispatch to a source declaration.
381381
exists(boolean static |
382382
result = this.getATarget(static) and
383-
not (
384-
result.applyGeneratedModel() and
385-
this.hasSourceTarget()
386-
)
383+
if this.hasSourceTarget() then result.hasManualModel() else any()
387384
|
388385
static = false
389386
or

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ private predicate fieldOrPropertyStore(Expr e, ContentSet c, Expr src, Expr q, b
848848
FlowSummaryImpl::Private::SummarizedCallableImpl sc,
849849
FlowSummaryImpl::Private::SummaryComponentStack input, ContentSet readSet
850850
|
851-
sc.propagatesFlow(input, _, _, _) and
851+
sc.propagatesFlow(input, _, _, _, _, _) and
852852
input.contains(FlowSummaryImpl::Private::SummaryComponent::content(readSet)) and
853853
c.getAStoreContent() = readSet.getAReadContent()
854854
)
@@ -1021,7 +1021,6 @@ private class InstanceCallable extends Callable {
10211021
private Location l;
10221022

10231023
InstanceCallable() {
1024-
this = any(DataFlowCallable dfc).asCallable(l) and
10251024
not this.(Modifiable).isStatic() and
10261025
// local functions and delegate capture `this` and should therefore
10271026
// not have a `this` parameter
@@ -1119,6 +1118,7 @@ private module Cached {
11191118
p = c.asCallable(_).(CallableUsedInSource).getAParameter()
11201119
} or
11211120
TInstanceParameterNode(InstanceCallable c, Location l) {
1121+
c = any(DataFlowCallable dfc).asCallable(l) and
11221122
c instanceof CallableUsedInSource and
11231123
l = c.getARelevantLocation()
11241124
} or

0 commit comments

Comments
 (0)