Skip to content

Commit c9d01bc

Browse files
committed
Shared: Sprinkle some predicate defaults and clean up.
1 parent a6b5645 commit c9d01bc

File tree

5 files changed

+22
-79
lines changed

5 files changed

+22
-79
lines changed

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

-16
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,6 @@ private module SummaryModelGeneratorInput implements SummaryModelGeneratorInputS
360360
result = "Element[" + ec.getIndirectionIndex() + "]"
361361
)
362362
}
363-
364-
predicate isUninterestingForDataFlowModels(Callable api) { none() }
365-
366-
predicate isUninterestingForHeuristicDataFlowModels(Callable api) {
367-
isUninterestingForDataFlowModels(api)
368-
}
369363
}
370364

371365
private module SourceModelGeneratorInput implements SourceModelGeneratorInputSig {
@@ -377,11 +371,6 @@ private module SourceModelGeneratorInput implements SourceModelGeneratorInputSig
377371
SourceTargetApi() { relevant(this) and not hasManualSourceModel(this) }
378372
}
379373

380-
predicate irrelevantSourceSinkApi(Callable source, SourceTargetApi api) { none() }
381-
382-
bindingset[kind]
383-
predicate isRelevantSourceKind(string kind) { any() }
384-
385374
predicate sourceNode = ExternalFlow::sourceNode/2;
386375
}
387376

@@ -396,8 +385,6 @@ private module SinkModelGeneratorInput implements SinkModelGeneratorInputSig {
396385
SinkTargetApi() { relevant(this) and not hasManualSinkModel(this) }
397386
}
398387

399-
predicate sinkModelSanitizer(DataFlow::Node node) { none() }
400-
401388
predicate apiSource(DataFlow::Node source) {
402389
DataFlowPrivate::nodeHasOperand(source, any(DataFlow::FieldAddress fa), 1)
403390
or
@@ -416,9 +403,6 @@ private module SinkModelGeneratorInput implements SinkModelGeneratorInputSig {
416403
result = qualifierString()
417404
}
418405

419-
bindingset[kind]
420-
predicate isRelevantSinkKind(string kind) { any() }
421-
422406
predicate sinkNode = ExternalFlow::sinkNode/2;
423407
}
424408

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

-10
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,6 @@ module SummaryModelGeneratorInput implements SummaryModelGeneratorInputSig {
234234
api = any(FlowSummaryImpl::Public::NeutralSummaryCallable sc | sc.hasManualModel())
235235
}
236236

237-
predicate isUninterestingForDataFlowModels(Callable api) { none() }
238-
239237
predicate isUninterestingForHeuristicDataFlowModels(Callable api) { isHigherOrder(api) }
240238

241239
class SummaryTargetApi extends Callable {
@@ -356,9 +354,6 @@ private module SourceModelGeneratorInput implements SourceModelGeneratorInputSig
356354
)
357355
}
358356

359-
bindingset[kind]
360-
predicate isRelevantSourceKind(string kind) { any() }
361-
362357
predicate sourceNode = ExternalFlow::sourceNode/2;
363358
}
364359

@@ -372,8 +367,6 @@ private module SinkModelGeneratorInput implements SinkModelGeneratorInputSig {
372367
SinkTargetApi() { relevant(this) and not hasManualSinkModel(this) }
373368
}
374369

375-
predicate sinkModelSanitizer(DataFlow::Node node) { none() }
376-
377370
private predicate isRelevantMemberAccess(DataFlow::Node node) {
378371
exists(CS::MemberAccess access | access = node.asExpr() |
379372
access.hasThisQualifier() and
@@ -400,9 +393,6 @@ private module SinkModelGeneratorInput implements SinkModelGeneratorInputSig {
400393
result = qualifierString()
401394
}
402395

403-
bindingset[kind]
404-
predicate isRelevantSinkKind(string kind) { any() }
405-
406396
predicate sinkNode = ExternalFlow::sinkNode/2;
407397
}
408398

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

-7
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ module SummaryModelGeneratorInput implements SummaryModelGeneratorInputSig {
211211
api.getDeclaringType() instanceof J::Interface and not exists(api.getBody())
212212
}
213213

214-
predicate isUninterestingForHeuristicDataFlowModels(Callable api) { none() }
215-
216214
predicate isAdditionalContentFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
217215
TaintTracking::defaultAdditionalTaintStep(node1, node2, _) and
218216
not exists(DataFlow::Content f |
@@ -264,11 +262,6 @@ private module SourceModelGeneratorInput implements SourceModelGeneratorInputSig
264262
SourceTargetApi() { relevant(this) and not hasManualSourceModel(this) }
265263
}
266264

267-
predicate irrelevantSourceSinkApi(Callable source, SourceTargetApi api) { none() }
268-
269-
bindingset[kind]
270-
predicate isRelevantSourceKind(string kind) { any() }
271-
272265
predicate sourceNode = ExternalFlow::sourceNode/2;
273266
}
274267

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

-15
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ private module SummaryModelGeneratorInput implements SummaryModelGeneratorInputS
123123

124124
Parameter asParameter(NodeExtended node) { result = node.asParameter() }
125125

126-
predicate isUninterestingForDataFlowModels(Callable api) { none() }
127-
128-
predicate isUninterestingForHeuristicDataFlowModels(Callable api) { none() }
129-
130126
predicate isAdditionalContentFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) { none() }
131127

132128
predicate isField(DataFlow::ContentSet c) {
@@ -169,12 +165,6 @@ private module SourceModelGeneratorInput implements SourceModelGeneratorInputSig
169165
SourceTargetApi() { relevant(this) }
170166
}
171167

172-
bindingset[sourceEnclosing, api]
173-
predicate irrelevantSourceSinkApi(Callable sourceEnclosing, SourceTargetApi api) { none() }
174-
175-
bindingset[kind]
176-
predicate isRelevantSourceKind(string kind) { any() }
177-
178168
predicate sourceNode(DataFlow::Node node, string kind) { FlowSource::sourceNode(node, kind) }
179169
}
180170

@@ -183,8 +173,6 @@ private module SinkModelGeneratorInput implements SinkModelGeneratorInputSig {
183173
SinkTargetApi() { relevant(this) }
184174
}
185175

186-
predicate sinkModelSanitizer(DataFlow::Node node) { none() }
187-
188176
/**
189177
* Holds if `source` is an API entrypoint, i.e., a source of input where data
190178
* can flow in to a library. This is used for creating sink models, as we
@@ -197,9 +185,6 @@ private module SinkModelGeneratorInput implements SinkModelGeneratorInputSig {
197185
result = "Argument[" + source.(Node::SourceParameterNode).getPosition().toString() + "]"
198186
}
199187

200-
bindingset[kind]
201-
predicate isRelevantSinkKind(string kind) { any() }
202-
203188
predicate sinkNode(DataFlow::Node node, string kind) { FlowSink::sinkNode(node, kind) }
204189
}
205190

shared/mad/codeql/mad/modelgenerator/internal/ModelGeneratorImpl.qll

+22-31
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ module MakeModelGeneratorFactory<
295295
*
296296
* This serves as an extra filter for the `relevant` predicate.
297297
*/
298-
predicate isUninterestingForDataFlowModels(Callable api);
298+
default predicate isUninterestingForDataFlowModels(Callable api) { none() }
299299

300300
/**
301301
* Holds if it is irrelevant to generate models for `api` based on the heuristic
@@ -304,7 +304,7 @@ module MakeModelGeneratorFactory<
304304
* This serves as an extra filter for the `relevant`
305305
* and `isUninterestingForDataFlowModels` predicates.
306306
*/
307-
predicate isUninterestingForHeuristicDataFlowModels(Callable api);
307+
default predicate isUninterestingForHeuristicDataFlowModels(Callable api) { none() }
308308
}
309309

310310
/**
@@ -940,24 +940,20 @@ module MakeModelGeneratorFactory<
940940
*/
941941
class SourceTargetApi extends Callable;
942942

943-
/**
944-
* Holds if it is not relevant to generate a source model for `api`, even
945-
* if flow is detected from a node within `source` to a sink within `api`.
946-
*/
947-
bindingset[sourceEnclosing, api]
948-
predicate irrelevantSourceSinkApi(Callable sourceEnclosing, SourceTargetApi api);
949-
950-
/**
951-
* Holds if `kind` is a relevant source kind for creating source models.
952-
*/
953-
bindingset[kind]
954-
predicate isRelevantSourceKind(string kind);
955-
956943
/**
957944
* Holds if `node` is specified as a source with the given kind in a MaD flow
958945
* model.
959946
*/
960947
predicate sourceNode(Lang::Node node, string kind);
948+
949+
/**
950+
* Holds if it is not relevant to generate a source model for `api`, even
951+
* if flow is detected from a node within `source` to a sink within `api`.
952+
*/
953+
bindingset[sourceEnclosing, api]
954+
default predicate irrelevantSourceSinkApi(Callable sourceEnclosing, SourceTargetApi api) {
955+
none()
956+
}
961957
}
962958

963959
/**
@@ -970,31 +966,31 @@ module MakeModelGeneratorFactory<
970966
class SinkTargetApi extends Callable;
971967

972968
/**
973-
* Gets the MaD input string representation of `source`.
969+
* Holds if `node` is specified as a sink with the given kind in a MaD flow
970+
* model.
974971
*/
975-
string getInputArgument(Lang::Node source);
972+
predicate sinkNode(Lang::Node node, string kind);
976973

977974
/**
978-
* Holds if `node` is a sanitizer for sink model construction.
975+
* Gets the MaD input string representation of `source`.
979976
*/
980-
predicate sinkModelSanitizer(Lang::Node node);
977+
string getInputArgument(Lang::Node source);
981978

982979
/**
983980
* Holds if `source` is an api entrypoint relevant for creating sink models.
984981
*/
985982
predicate apiSource(Lang::Node source);
986983

987984
/**
988-
* Holds if `kind` is a relevant sink kind for creating sink models.
985+
* Holds if `node` is a sanitizer for sink model construction.
989986
*/
990-
bindingset[kind]
991-
predicate isRelevantSinkKind(string kind);
987+
default predicate sinkModelSanitizer(Lang::Node node) { none() }
992988

993989
/**
994-
* Holds if `node` is specified as a sink with the given kind in a MaD flow
995-
* model.
990+
* Holds if `kind` is a relevant sink kind for creating sink models.
996991
*/
997-
predicate sinkNode(Lang::Node node, string kind);
992+
bindingset[kind]
993+
default predicate isRelevantSinkKind(string kind) { any() }
998994
}
999995

1000996
/**
@@ -1029,12 +1025,7 @@ module MakeModelGeneratorFactory<
10291025
* via its return (then the API itself becomes a source).
10301026
*/
10311027
module PropagateFromSourceConfig implements DataFlow::ConfigSig {
1032-
predicate isSource(DataFlow::Node source) {
1033-
exists(string kind |
1034-
isRelevantSourceKind(kind) and
1035-
sourceNode(source, kind)
1036-
)
1037-
}
1028+
predicate isSource(DataFlow::Node source) { sourceNode(source, _) }
10381029

10391030
predicate isSink(DataFlow::Node sink) {
10401031
sink instanceof ReturnNodeExt and

0 commit comments

Comments
 (0)