From b5c596b2ce2450e1969ca751fa3ff3ce47155bf9 Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Thu, 24 Apr 2025 15:32:12 +0200 Subject: [PATCH] Shared: Split model printing of summaries and sources/sinks into separate param modules. --- .../CaptureTypeBasedSummaryModels.qll | 6 ++-- .../CaptureTypeBasedSummaryModels.qll | 6 ++-- .../internal/ModelGeneratorImpl.qll | 31 +++++++++++-------- .../modelgenerator/internal/ModelPrinting.qll | 28 ++++++++++++----- 4 files changed, 42 insertions(+), 29 deletions(-) diff --git a/csharp/ql/src/utils/modelgenerator/internal/CaptureTypeBasedSummaryModels.qll b/csharp/ql/src/utils/modelgenerator/internal/CaptureTypeBasedSummaryModels.qll index f7b0633ddd3..62286c27888 100644 --- a/csharp/ql/src/utils/modelgenerator/internal/CaptureTypeBasedSummaryModels.qll +++ b/csharp/ql/src/utils/modelgenerator/internal/CaptureTypeBasedSummaryModels.qll @@ -177,15 +177,13 @@ private predicate output(Callable callable, TypeParameter tp, string output) { delegateSink(callable, tp, output) } -private module ModelPrintingInput implements ModelPrintingSig { +private module ModelPrintingInput implements ModelPrintingSummarySig { class SummaryApi = TypeBasedFlowTargetApi; - class SourceOrSinkApi = TypeBasedFlowTargetApi; - string getProvenance() { result = "tb-generated" } } -private module Printing = ModelPrinting; +private module Printing = ModelPrintingSummary; /** * A class of callables that are relevant generating summaries for based diff --git a/java/ql/src/utils/modelgenerator/internal/CaptureTypeBasedSummaryModels.qll b/java/ql/src/utils/modelgenerator/internal/CaptureTypeBasedSummaryModels.qll index 36aec805319..9145a077907 100644 --- a/java/ql/src/utils/modelgenerator/internal/CaptureTypeBasedSummaryModels.qll +++ b/java/ql/src/utils/modelgenerator/internal/CaptureTypeBasedSummaryModels.qll @@ -284,15 +284,13 @@ private predicate output(Callable callable, TypeVariable tv, string output) { functionalSink(callable, tv, output) } -module ModelPrintingInput implements ModelPrintingSig { +module ModelPrintingInput implements ModelPrintingSummarySig { class SummaryApi = TypeBasedFlowTargetApi; - class SourceOrSinkApi = ModelGeneratorInput::SourceOrSinkTargetApi; - string getProvenance() { result = "tb-generated" } } -private module Printing = ModelPrinting; +private module Printing = ModelPrintingSummary; /** * A class of callables that are relevant generating summaries for based diff --git a/shared/mad/codeql/mad/modelgenerator/internal/ModelGeneratorImpl.qll b/shared/mad/codeql/mad/modelgenerator/internal/ModelGeneratorImpl.qll index b9592964f93..59f53c2b1c9 100644 --- a/shared/mad/codeql/mad/modelgenerator/internal/ModelGeneratorImpl.qll +++ b/shared/mad/codeql/mad/modelgenerator/internal/ModelGeneratorImpl.qll @@ -370,20 +370,27 @@ module MakeModelGenerator< * based on heuristic data flow. */ module Heuristic { - private module ModelPrintingInput implements Printing::ModelPrintingSig { + private module ModelPrintingSummaryInput implements Printing::ModelPrintingSummarySig { class SummaryApi = DataFlowSummaryTargetApi; + string getProvenance() { result = "df-generated" } + } + + module ModelPrintingSummary = Printing::ModelPrintingSummary; + + private module ModelPrintingSourceOrSinkInput implements Printing::ModelPrintingSourceOrSinkSig { class SourceOrSinkApi = SourceOrSinkTargetApi; string getProvenance() { result = "df-generated" } } - module ModelPrinting = Printing::ModelPrinting; - private string getOutput(ReturnNodeExt node) { result = PrintReturnNodeExt::getOutput(node) } + private module ModelPrintingSourceOrSink = + Printing::ModelPrintingSourceOrSink; + /** * Holds if data can flow from `node1` to `node2` either via a read or a write of an intermediate field `f`. */ @@ -419,7 +426,7 @@ module MakeModelGenerator< api = returnNodeEnclosingCallable(ret) and isOwnInstanceAccessNode(ret) ) and - result = ModelPrinting::asLiftedValueModel(api, qualifierString(), "ReturnValue") + result = ModelPrintingSummary::asLiftedValueModel(api, qualifierString(), "ReturnValue") } private int accessPathLimit0() { result = 2 } @@ -539,7 +546,7 @@ module MakeModelGenerator< input = parameterNodeAsInput(p) and output = getOutput(returnNodeExt) and input != output and - result = ModelPrinting::asLiftedTaintModel(api, input, output) + result = ModelPrintingSummary::asLiftedTaintModel(api, input, output) ) } @@ -572,7 +579,7 @@ module MakeModelGenerator< exists(captureFlow(api0)) and api0.lift() = api.lift() ) and api.isRelevant() and - result = ModelPrinting::asNeutralSummaryModel(api) + result = ModelPrintingSummary::asNeutralSummaryModel(api) } /** @@ -617,7 +624,7 @@ module MakeModelGenerator< sourceNode(source, kind) and api = getEnclosingCallable(sink) and not irrelevantSourceSinkApi(getEnclosingCallable(source), api) and - result = ModelPrinting::asSourceModel(api, getOutput(sink), kind) + result = ModelPrintingSourceOrSink::asSourceModel(api, getOutput(sink), kind) ) } @@ -663,7 +670,7 @@ module MakeModelGenerator< PropagateToSink::flow(src, sink) and sinkNode(sink, kind) and api = getEnclosingCallable(src) and - result = ModelPrinting::asSinkModel(api, asInputArgument(src), kind) + result = ModelPrintingSourceOrSink::asSinkModel(api, asInputArgument(src), kind) ) } } @@ -703,15 +710,13 @@ module MakeModelGenerator< private module PropagateContentFlow = ContentDataFlow::Global; - private module ContentModelPrintingInput implements Printing::ModelPrintingSig { + private module ContentModelPrintingInput implements Printing::ModelPrintingSummarySig { class SummaryApi = DataFlowSummaryTargetApi; - class SourceOrSinkApi = SourceOrSinkTargetApi; - string getProvenance() { result = "dfc-generated" } } - private module ContentModelPrinting = Printing::ModelPrinting; + private module ContentModelPrinting = Printing::ModelPrintingSummary; private string getContentOutput(ReturnNodeExt node) { result = PrintReturnNodeExt::getOutput(node) @@ -1075,6 +1080,6 @@ module MakeModelGenerator< ) ) and api.isRelevant() and - result = Heuristic::ModelPrinting::asNeutralSummaryModel(api) + result = Heuristic::ModelPrintingSummary::asNeutralSummaryModel(api) } } diff --git a/shared/mad/codeql/mad/modelgenerator/internal/ModelPrinting.qll b/shared/mad/codeql/mad/modelgenerator/internal/ModelPrinting.qll index 0ab92f7032b..fc1e0113d1d 100644 --- a/shared/mad/codeql/mad/modelgenerator/internal/ModelPrinting.qll +++ b/shared/mad/codeql/mad/modelgenerator/internal/ModelPrinting.qll @@ -16,7 +16,7 @@ signature module ModelPrintingLangSig { } module ModelPrintingImpl { - signature module ModelPrintingSig { + signature module ModelPrintingSummarySig { /** * The class of APIs relevant for model generation. */ @@ -24,6 +24,16 @@ module ModelPrintingImpl { Lang::Callable lift(); } + /** + * Gets the string representation of the provenance of the models. + */ + string getProvenance(); + } + + signature module ModelPrintingSourceOrSinkSig { + /** + * The class of APIs relevant for model generation. + */ class SourceOrSinkApi extends Lang::Callable; /** @@ -32,14 +42,14 @@ module ModelPrintingImpl { string getProvenance(); } - module ModelPrinting { - /** - * Computes the first columns for MaD rows used for summaries, sources and sinks. - */ - private string asPartialModel(Lang::Callable api) { - result = strictconcat(int i | | Lang::partialModelRow(api, i), ";" order by i) + ";" - } + /** + * Computes the first columns for MaD rows used for summaries, sources and sinks. + */ + private string asPartialModel(Lang::Callable api) { + result = strictconcat(int i | | Lang::partialModelRow(api, i), ";" order by i) + ";" + } + module ModelPrintingSummary { /** * Computes the first columns for neutral MaD rows. */ @@ -106,7 +116,9 @@ module ModelPrintingImpl { preservesValue = false and result = asSummaryModel(api, input, output, "taint", lift) } + } + module ModelPrintingSourceOrSink { /** * Gets the sink model for `api` with `input` and `kind`. */