Skip to content

Commit da58b2a

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Shared: move shared file to 'shared' folder and add parameterized module for 'getInvalidModelKind'
1 parent 5a23421 commit da58b2a

File tree

26 files changed

+308
-1182
lines changed

26 files changed

+308
-1182
lines changed

config/identical-files.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -598,14 +598,5 @@
598598
"EncryptionKeySizes Python/Java": [
599599
"python/ql/lib/semmle/python/security/internal/EncryptionKeySizes.qll",
600600
"java/ql/lib/semmle/code/java/security/internal/EncryptionKeySizes.qll"
601-
],
602-
"SharedModelValidation Java/C#/Go/JS/Python/Ruby/Swift": [
603-
"java/ql/lib/semmle/code/java/dataflow/internal/SharedModelValidation.qll",
604-
"csharp/ql/lib/semmle/code/csharp/dataflow/internal/SharedModelValidation.qll",
605-
"go/ql/lib/semmle/go/dataflow/internal/SharedModelValidation.qll",
606-
"swift/ql/lib/codeql/swift/dataflow/internal/SharedModelValidation.qll",
607-
"javascript/ql/lib/semmle/javascript/frameworks/data/internal/SharedModelValidation.qll",
608-
"python/ql/lib/semmle/python/frameworks/data/internal/SharedModelValidation.qll",
609-
"ruby/ql/lib/codeql/ruby/frameworks/data/internal/SharedModelValidation.qll"
610601
]
611602
}

csharp/ql/lib/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extractor: csharp
66
library: true
77
upgrades: upgrades
88
dependencies:
9+
codeql/mad: ${workspace}
910
codeql/ssa: ${workspace}
1011
codeql/tutorial: ${workspace}
1112
codeql/util: ${workspace}

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

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private import internal.DataFlowPublic
9595
private import internal.FlowSummaryImpl::Public
9696
private import internal.FlowSummaryImpl::Private::External
9797
private import internal.FlowSummaryImplSpecific
98-
private import internal.SharedModelValidation
98+
private import codeql.mad.ModelValidation as SharedModelVal
9999

100100
/** Holds if a source model exists for the given parameters. */
101101
predicate sourceModel = Extensions::sourceModel/9;
@@ -205,32 +205,20 @@ module ModelValidation {
205205
)
206206
}
207207

208-
/** Gets an error message relating to an invalid kind in a model. */
209-
private string getInvalidModelKind() {
210-
exists(string kind | summaryModel(_, _, _, _, _, _, _, _, kind, _) |
211-
not kind instanceof ValidSummaryKind and
212-
result = "Invalid kind \"" + kind + "\" in summary model."
213-
)
214-
or
215-
exists(string kind, string msg | sinkModel(_, _, _, _, _, _, _, kind, _) |
216-
not kind instanceof ValidSinkKind and
217-
msg = "Invalid kind \"" + kind + "\" in sink model." and
218-
// The part of this message that refers to outdated sink kinds can be deleted after June 1st, 2024.
219-
if kind instanceof OutdatedSinkKind
220-
then result = msg + " " + kind.(OutdatedSinkKind).outdatedMessage()
221-
else result = msg
222-
)
223-
or
224-
exists(string kind | sourceModel(_, _, _, _, _, _, _, kind, _) |
225-
not kind instanceof ValidSourceKind and
226-
result = "Invalid kind \"" + kind + "\" in source model."
227-
)
228-
or
229-
exists(string kind | neutralModel(_, _, _, _, kind, _) |
230-
not kind instanceof ValidNeutralKind and
231-
result = "Invalid kind \"" + kind + "\" in neutral model."
232-
)
233-
}
208+
/** Holds if a summary model exists for the given `kind`. */
209+
private predicate summaryKind(string kind) { summaryModel(_, _, _, _, _, _, _, _, kind, _) }
210+
211+
/** Holds if a sink model exists for the given `kind`. */
212+
private predicate sinkKind(string kind) { sinkModel(_, _, _, _, _, _, _, kind, _) }
213+
214+
/** Holds if a source model exists for the given `kind`. */
215+
private predicate sourceKind(string kind) { sourceModel(_, _, _, _, _, _, _, kind, _) }
216+
217+
/** Holds if a neutral model exists for the given `kind`. */
218+
private predicate neutralKind(string kind) { neutralModel(_, _, _, _, kind, _) }
219+
220+
private module KindVal =
221+
SharedModelVal::KindValidation<summaryKind/1, sinkKind/1, sourceKind/1, neutralKind/1>;
234222

235223
private string getInvalidModelSignature() {
236224
exists(
@@ -273,7 +261,7 @@ module ModelValidation {
273261
msg =
274262
[
275263
getInvalidModelSignature(), getInvalidModelInput(), getInvalidModelOutput(),
276-
getInvalidModelKind()
264+
KindVal::getInvalidModelKind()
277265
]
278266
}
279267
}

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

Lines changed: 0 additions & 143 deletions
This file was deleted.

go/ql/lib/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extractor: go
66
library: true
77
upgrades: upgrades
88
dependencies:
9+
codeql/mad: ${workspace}
910
codeql/tutorial: ${workspace}
1011
codeql/util: ${workspace}
1112
dataExtensions:

go/ql/lib/semmle/go/dataflow/ExternalFlow.qll

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private import internal.FlowSummaryImpl::Private::External
6868
private import internal.FlowSummaryImplSpecific
6969
private import internal.AccessPathSyntax
7070
private import FlowSummary
71-
private import internal.SharedModelValidation
71+
private import codeql.mad.ModelValidation as SharedModelVal
7272

7373
/**
7474
* A module importing the frameworks that provide external flow data,
@@ -189,27 +189,20 @@ module ModelValidation {
189189
)
190190
}
191191

192-
/** Gets an error message relating to an invalid kind in a model. */
193-
private string getInvalidModelKind() {
194-
exists(string kind | summaryModel(_, _, _, _, _, _, _, _, kind, _) |
195-
not kind instanceof ValidSummaryKind and
196-
result = "Invalid kind \"" + kind + "\" in summary model."
197-
)
198-
or
199-
exists(string kind, string msg | sinkModel(_, _, _, _, _, _, _, kind, _) |
200-
not kind instanceof ValidSinkKind and
201-
msg = "Invalid kind \"" + kind + "\" in sink model." and
202-
// The part of this message that refers to outdated sink kinds can be deleted after June 1st, 2024.
203-
if kind instanceof OutdatedSinkKind
204-
then result = msg + " " + kind.(OutdatedSinkKind).outdatedMessage()
205-
else result = msg
206-
)
207-
or
208-
exists(string kind | sourceModel(_, _, _, _, _, _, _, kind, _) |
209-
not kind instanceof ValidSourceKind and
210-
result = "Invalid kind \"" + kind + "\" in source model."
211-
)
212-
}
192+
/** Holds if a summary model exists for the given `kind`. */
193+
private predicate summaryKind(string kind) { summaryModel(_, _, _, _, _, _, _, _, kind, _) }
194+
195+
/** Holds if a sink model exists for the given `kind`. */
196+
private predicate sinkKind(string kind) { sinkModel(_, _, _, _, _, _, _, kind, _) }
197+
198+
/** Holds if a source model exists for the given `kind`. */
199+
private predicate sourceKind(string kind) { sourceModel(_, _, _, _, _, _, _, kind, _) }
200+
201+
/** Holds if a neutral model exists for the given `kind`. */
202+
private predicate neutralKind(string kind) { none() }
203+
204+
private module KindVal =
205+
SharedModelVal::KindValidation<summaryKind/1, sinkKind/1, sourceKind/1, neutralKind/1>;
213206

214207
private string getInvalidModelSignature() {
215208
exists(
@@ -247,7 +240,7 @@ module ModelValidation {
247240
msg =
248241
[
249242
getInvalidModelSignature(), getInvalidModelInput(), getInvalidModelOutput(),
250-
getInvalidModelKind()
243+
KindVal::getInvalidModelKind()
251244
]
252245
}
253246
}

0 commit comments

Comments
 (0)