Skip to content

Commit 4193b7e

Browse files
michaelnebelowen-mc
authored andcommitted
Allow grouping import paths for models-as-data
1 parent f183382 commit 4193b7e

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

go/ql/lib/ext/empty.model.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ extensions:
1717
pack: codeql/go-all
1818
extensible: neutralModel
1919
data: []
20+
- addsTo:
21+
pack: codeql/go-all
22+
extensible: packageGrouping
23+
data: []

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

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
*/
7979

8080
private import go
81-
import internal.ExternalFlowExtensions
81+
import internal.ExternalFlowExtensions as FlowExtensions
8282
private import FlowSummary as FlowSummary
8383
private import internal.DataFlowPrivate
8484
private import internal.FlowSummaryImpl
@@ -87,6 +87,82 @@ private import internal.FlowSummaryImpl::Private
8787
private import internal.FlowSummaryImpl::Private::External
8888
private import codeql.mad.ModelValidation as SharedModelVal
8989

90+
/** Gets the prefix for a group of packages. */
91+
string groupPrefix() { result = "group:" }
92+
93+
/** Gets a group that `package` is in, according to `packageGrouping`. */
94+
private string getGroup(string package) {
95+
exists(string group |
96+
FlowExtensions::packageGrouping(group, package) and
97+
result = groupPrefix() + group
98+
)
99+
}
100+
101+
/**
102+
* Holds if a source model exists for the given parameters.
103+
*
104+
* Note that we consider all packages in the same group.
105+
*/
106+
predicate sourceModel(
107+
string package, string type, boolean subtypes, string name, string signature, string ext,
108+
string output, string kind, string provenance, QlBuiltins::ExtensionId madId
109+
) {
110+
FlowExtensions::sourceModel(package, type, subtypes, name, signature, ext, output, kind,
111+
provenance, madId)
112+
or
113+
// Also look for models that are defined for a group that `package` is part of.
114+
FlowExtensions::sourceModel(getGroup(package), type, subtypes, name, signature, ext, output, kind,
115+
provenance, madId)
116+
}
117+
118+
/**
119+
* Holds if a sink model exists for the given parameters.
120+
*
121+
* Note that we consider all packages in the same group.
122+
*/
123+
predicate sinkModel(
124+
string package, string type, boolean subtypes, string name, string signature, string ext,
125+
string input, string kind, string provenance, QlBuiltins::ExtensionId madId
126+
) {
127+
FlowExtensions::sinkModel(package, type, subtypes, name, signature, ext, input, kind, provenance,
128+
madId)
129+
or
130+
// Also look for models that are defined for a group that `package` is part of.
131+
FlowExtensions::sinkModel(getGroup(package), type, subtypes, name, signature, ext, input, kind,
132+
provenance, madId)
133+
}
134+
135+
/**
136+
* Holds if a summary model exists for the given parameters.
137+
*
138+
* Note that we consider all packages in the same group.
139+
*/
140+
predicate summaryModel(
141+
string package, string type, boolean subtypes, string name, string signature, string ext,
142+
string input, string output, string kind, string provenance, QlBuiltins::ExtensionId madId
143+
) {
144+
FlowExtensions::summaryModel(package, type, subtypes, name, signature, ext, input, output, kind,
145+
provenance, madId)
146+
or
147+
// Also look for models that are defined for a group that `package` is part of.
148+
FlowExtensions::summaryModel(getGroup(package), type, subtypes, name, signature, ext, input,
149+
output, kind, provenance, madId)
150+
}
151+
152+
/**
153+
* Holds if a neutral model exists for the given parameters.
154+
*
155+
* Note that we consider all packages in the same group.
156+
*/
157+
predicate neutralModel(
158+
string package, string type, string name, string signature, string kind, string provenance
159+
) {
160+
FlowExtensions::neutralModel(package, type, name, signature, kind, provenance)
161+
or
162+
// Also look for models that are defined for a group that `package` is part of.
163+
FlowExtensions::neutralModel(getGroup(package), type, name, signature, kind, provenance)
164+
}
165+
90166
/**
91167
* Holds if the given extension tuple `madId` should pretty-print as `model`.
92168
*

go/ql/lib/semmle/go/dataflow/internal/ExternalFlowExtensions.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ extensible predicate summaryModel(
3232
extensible predicate neutralModel(
3333
string package, string type, string name, string signature, string kind, string provenance
3434
);
35+
36+
/**
37+
* Holds if the package `package` is part of the group `group`.
38+
*/
39+
extensible predicate packageGrouping(string group, string package);

0 commit comments

Comments
 (0)