From 0915db4f6bdcffc6a9f311f63af95bd23d52f499 Mon Sep 17 00:00:00 2001 From: Anders Schack-Mulligen Date: Thu, 11 Dec 2025 08:20:13 +0100 Subject: [PATCH] C++/C#/Go: Use shared interpretModelForTest. --- .../semmle/code/cpp/dataflow/ExternalFlow.qll | 50 +++---------------- .../csharp/dataflow/internal/ExternalFlow.qll | 41 ++------------- go/ql/lib/semmle/go/dataflow/ExternalFlow.qll | 49 +++--------------- 3 files changed, 18 insertions(+), 122 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll b/cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll index 69e32d23ec1..b31578492bb 100644 --- a/cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll +++ b/cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll @@ -101,9 +101,14 @@ private import internal.FlowSummaryImpl private import internal.FlowSummaryImpl::Public private import internal.FlowSummaryImpl::Private private import internal.FlowSummaryImpl::Private::External -private import internal.ExternalFlowExtensions as Extensions +private import internal.ExternalFlowExtensions private import codeql.mad.ModelValidation as SharedModelVal private import codeql.util.Unit +private import codeql.mad.static.MaD as SharedMaD + +private module MaD = SharedMaD::ModelsAsData; + +import MaD /** * A unit class for adding additional source model rows. @@ -230,49 +235,6 @@ private predicate summaryModel0( ) } -/** - * Holds if the given extension tuple `madId` should pretty-print as `model`. - * - * This predicate should only be used in tests. - */ -predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) { - exists( - string namespace, string type, boolean subtypes, string name, string signature, string ext, - string output, string kind, string provenance - | - Extensions::sourceModel(namespace, type, subtypes, name, signature, ext, output, kind, - provenance, madId) - | - model = - "Source: " + namespace + "; " + type + "; " + subtypes + "; " + name + "; " + signature + "; " - + ext + "; " + output + "; " + kind + "; " + provenance - ) - or - exists( - string namespace, string type, boolean subtypes, string name, string signature, string ext, - string input, string kind, string provenance - | - Extensions::sinkModel(namespace, type, subtypes, name, signature, ext, input, kind, provenance, - madId) - | - model = - "Sink: " + namespace + "; " + type + "; " + subtypes + "; " + name + "; " + signature + "; " + - ext + "; " + input + "; " + kind + "; " + provenance - ) - or - exists( - string namespace, string type, boolean subtypes, string name, string signature, string ext, - string input, string output, string kind, string provenance - | - Extensions::summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, - provenance, madId) - | - model = - "Summary: " + namespace + "; " + type + "; " + subtypes + "; " + name + "; " + signature + - "; " + ext + "; " + input + "; " + output + "; " + kind + "; " + provenance - ) -} - /** * Holds if `input` is `input0`, but with all occurrences of `@` replaced * by `n` repetitions of `*` (and similarly for `output` and `output0`). diff --git a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/ExternalFlow.qll b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/ExternalFlow.qll index 87b28b76e99..04933e11282 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/ExternalFlow.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/ExternalFlow.qll @@ -101,44 +101,11 @@ private import semmle.code.csharp.dispatch.OverridableCallable private import semmle.code.csharp.frameworks.System private import codeql.dataflow.internal.AccessPathSyntax as AccessPathSyntax private import codeql.mad.ModelValidation as SharedModelVal +private import codeql.mad.static.MaD as SharedMaD -/** - * Holds if the given extension tuple `madId` should pretty-print as `model`. - * - * This predicate should only be used in tests. - */ -predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) { - exists( - string namespace, string type, boolean subtypes, string name, string signature, string ext, - string output, string kind, string provenance - | - sourceModel(namespace, type, subtypes, name, signature, ext, output, kind, provenance, madId) and - model = - "Source: " + namespace + "; " + type + "; " + subtypes + "; " + name + "; " + signature + "; " - + ext + "; " + output + "; " + kind + "; " + provenance - ) - or - exists( - string namespace, string type, boolean subtypes, string name, string signature, string ext, - string input, string kind, string provenance - | - sinkModel(namespace, type, subtypes, name, signature, ext, input, kind, provenance, madId) and - model = - "Sink: " + namespace + "; " + type + "; " + subtypes + "; " + name + "; " + signature + "; " + - ext + "; " + input + "; " + kind + "; " + provenance - ) - or - exists( - string namespace, string type, boolean subtypes, string name, string signature, string ext, - string input, string output, string kind, string provenance - | - summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, provenance, - madId) and - model = - "Summary: " + namespace + "; " + type + "; " + subtypes + "; " + name + "; " + signature + - "; " + ext + "; " + input + "; " + output + "; " + kind + "; " + provenance - ) -} +private module MaD = SharedMaD::ModelsAsData; + +import MaD private predicate relevantNamespace(string namespace) { sourceModel(namespace, _, _, _, _, _, _, _, _, _) or diff --git a/go/ql/lib/semmle/go/dataflow/ExternalFlow.qll b/go/ql/lib/semmle/go/dataflow/ExternalFlow.qll index 3228f424885..f09d6b15006 100644 --- a/go/ql/lib/semmle/go/dataflow/ExternalFlow.qll +++ b/go/ql/lib/semmle/go/dataflow/ExternalFlow.qll @@ -86,7 +86,7 @@ */ private import go -import internal.ExternalFlowExtensions as FlowExtensions +private import internal.ExternalFlowExtensions private import FlowSummary as FlowSummary private import internal.DataFlowPrivate private import internal.FlowSummaryImpl @@ -94,6 +94,13 @@ private import internal.FlowSummaryImpl::Public as Public private import internal.FlowSummaryImpl::Private private import internal.FlowSummaryImpl::Private::External private import codeql.mad.ModelValidation as SharedModelVal +private import codeql.mad.static.MaD as SharedMaD + +private module MaD = SharedMaD::ModelsAsData; + +import MaD + +module FlowExtensions = Extensions; /** Gets the prefix for a group of packages. */ private string groupPrefix() { result = "group:" } @@ -178,46 +185,6 @@ predicate neutralModel( ) } -/** - * Holds if the given extension tuple `madId` should pretty-print as `model`. - * - * This predicate should only be used in tests. - */ -predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) { - exists( - string package, string type, boolean subtypes, string name, string signature, string ext, - string output, string kind, string provenance - | - FlowExtensions::sourceModel(package, type, subtypes, name, signature, ext, output, kind, - provenance, madId) and - model = - "Source: " + package + "; " + type + "; " + subtypes + "; " + name + "; " + signature + "; " + - ext + "; " + output + "; " + kind + "; " + provenance - ) - or - exists( - string package, string type, boolean subtypes, string name, string signature, string ext, - string input, string kind, string provenance - | - FlowExtensions::sinkModel(package, type, subtypes, name, signature, ext, input, kind, - provenance, madId) and - model = - "Sink: " + package + "; " + type + "; " + subtypes + "; " + name + "; " + signature + "; " + - ext + "; " + input + "; " + kind + "; " + provenance - ) - or - exists( - string package, string type, boolean subtypes, string name, string signature, string ext, - string input, string output, string kind, string provenance - | - FlowExtensions::summaryModel(package, type, subtypes, name, signature, ext, input, output, kind, - provenance, madId) and - model = - "Summary: " + package + "; " + type + "; " + subtypes + "; " + name + "; " + signature + "; " + - ext + "; " + input + "; " + output + "; " + kind + "; " + provenance - ) -} - bindingset[p] private string cleanPackage(string p) { exists(string noPrefix |