-
Notifications
You must be signed in to change notification settings - Fork 5
/
gen_queries.py
executable file
·279 lines (240 loc) · 10 KB
/
gen_queries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/usr/bin/env python3
import sys
import argparse
"""
To update this function when we reach a new ESR, just add the new ESR version at the end of knownESRs.
Then add some new expected values to the expected variable in sanityCheck to make sure it works as expected.
Hopefully no code update is needed.
You may wonder why we have the versions as strings as the reurn from this function.
It's because 68.10 is mathematically equal to 68.1 but they are different versions.
"""
def versionToESRs(version):
version = int(version)
knownESRs = [60, 68, 78, 91, 102, 115, 128]
twoESRVersions = []
for x in knownESRs:
twoESRVersions.append(x)
twoESRVersions.append(x+1)
# We have a three-release overlap post-78 due to shortened release cycles
if x >= 78:
twoESRVersions.append(x+2)
for x in range(131, 137):
twoESRVersions.append(x)
twoESRs = True if version in twoESRVersions else False
subsetOfESRs = [x for x in knownESRs if x <= version]
if twoESRs:
firstESRPointRelease = str(subsetOfESRs[-2]) + "." + str(version - subsetOfESRs[-2])
secondESRPointRelease = str(subsetOfESRs[-1]) + "." + str(version - subsetOfESRs[-1])
return [firstESRPointRelease, secondESRPointRelease]
else:
pointRelease = str(subsetOfESRs[-1]) + "." + str(version - subsetOfESRs[-1])
return [pointRelease]
def getPriorVersion(version):
if "." in version:
return f'{version.split(".")[0]}.{int(version.split(".")[1]) - 1}'
else:
return str(int(version) - 1)
def sanityCheck():
expected = [
(68, ["60.8", "68.0"]),
(69, ["60.9", "68.1"]),
(70, ["68.2"]),
(71, ["68.3"]),
(72, ["68.4"]),
(73, ["68.5"]),
(74, ["68.6"]),
(75, ["68.7"]),
(76, ["68.8"]),
(77, ["68.9"]),
(78, ["68.10", "78.0"]),
(79, ["68.11", "78.1"]),
(80, ["68.12", "78.2"]),
(81, ["78.3"]),
(129, ["115.14", "128.1"]),
(132, ["115.17", "128.4"]),
(136, ["115.21", "128.8"]),
(137, ["128.9"])
]
for e in expected:
if versionToESRs(e[0]) != e[1]:
print("Sanity Check: Did not match versionToESRs(" + str(e[0]) + ") ==", e[1], "Got", versionToESRs(e[0]))
sys.exit(1)
#------------------------
def toAssign(version, primaryVersion, esr):
if esr:
return toAssignESR(version, primaryVersion)
else:
return toAssignMain(version)
def toAssignMain(version):
prior = getPriorVersion(version).replace(".", "")
return "https://bugzilla.mozilla.org/buglist.cgi?" + \
\
"&f2=cf_status_firefox" + prior + "&o2=nowords&v2=fixed%20verified%20disabled%20unaffected" + \
\
"&f5=cf_status_firefox" + version + "&o5=anywords&v5=fixed%20verified" + \
\
"&f9=status_whiteboard&o9=notsubstring&v9=adv-main" + version + \
\
"&f11=OP&j11=OR" + \
"&f12=keywords&o12=substring&v12=sec-" + \
"&f13=bug_group&o13=substring&v13=core-security" + \
"&f14=CP"
def toAssignESR(esrVersion, primaryVersion):
esrBaseVersion = esrVersion.split(".")[0]
return "https://bugzilla.mozilla.org/buglist.cgi?" + \
\
"&f2=cf_tracking_firefox_esr" + esrBaseVersion + "&o2=equals&v2=" + primaryVersion + "%2B" + \
\
"&f5=status_whiteboard&o5=notsubstring&v5=adv-esr" + esrVersion + \
\
"&f7=OP&j7=OR" + \
"&f8=keywords&o8=substring&v8=sec-" + \
"&f9=bug_group&o9=substring&v9=core-security" + \
"&f10=CP"
#------------------------
def toWrite(version, primaryVersion, esr):
if esr:
return toWriteESR(version, primaryVersion)
else:
return toWriteMain(version)
def toWriteMain(version):
prior = getPriorVersion(version).replace(".", "")
return "https://bugzilla.mozilla.org/buglist.cgi?" + \
\
"&f2=cf_status_firefox" + prior + "&o2=nowords&v2=fixed%20verified%20disabled%20unaffected" + \
\
"&f5=cf_status_firefox" + version + "&o5=anywords&v5=fixed%20verified" + \
\
"&f9=status_whiteboard&o9=substring&v9=adv-main" + version + "%2B" + \
"&f10=status_whiteboard&o10=notsubstring&v10=adv-main" + version + "%2Br" + \
\
"&f13=attachments.description&o13=equals&v13=advisory.txt&n13=1" + \
\
"&f15=OP&j15=OR" + \
"&f16=keywords&o16=substring&v16=sec-" + \
"&f17=bug_group&o17=substring&v17=core-security" + \
"&f18=CP"
def toWriteESR(esrVersion, primaryVersion):
esrBaseVersion = esrVersion.split(".")[0]
return "https://bugzilla.mozilla.org/buglist.cgi?" + \
\
"&f2=cf_tracking_firefox_esr" + esrBaseVersion + "&o2=equals&v2=" + primaryVersion + "%2B" + \
\
"&f5=status_whiteboard&o5=substring&v5=adv-esr" + esrVersion + "%2B" + \
"&f6=status_whiteboard&o6=notsubstring&v6=adv-esr" + esrVersion + "%2Br" + \
\
"&f9=attachments.description&o9=equals&v9=advisory.txt&n9=1" + \
\
"&f11=OP&j11=OR" + \
"&f12=keywords&o12=substring&v12=sec-" + \
"&f13=bug_group&o13=substring&v13=core-security" + \
"&f14=CP"
#------------------------
def rollupList(version, primaryVersion, esr):
if esr:
return rollupListESR(version)
else:
return rollupListMain(version)
def rollupListMain(version):
return "https://bugzilla.mozilla.org/buglist.cgi?" + \
"&f1=status_whiteboard&o1=substring&v1=adv-main" + version + "%2Br"
def rollupListESR(esrVersion):
return "https://bugzilla.mozilla.org/buglist.cgi?" + \
"&f1=status_whiteboard&o1=substring&v1=adv-esr" + esrVersion + "%2Br"
def rollupListMainAndESR(primaryVersion, esrVersion):
return "https://bugzilla.mozilla.org/buglist.cgi?" + \
"&f2=status_whiteboard&o2=substring&v2=adv-main" + primaryVersion + "%2Br" + \
"&f3=status_whiteboard&o3=substring&v3=adv-esr" + esrVersion + "%2Br"
def rollupListMainOnly(primaryVersion, allEsrVersions):
s = "https://bugzilla.mozilla.org/buglist.cgi?" + \
"&f2=status_whiteboard&o2=substring&v2=adv-main" + primaryVersion + "%2Br" + \
"&f3=status_whiteboard&o3=notsubstring&v3=adv-esr" + allEsrVersions[0] + "%2Br"
if len(allEsrVersions) > 1:
s += "&f4=status_whiteboard&o4=notsubstring&v4=adv-esr" + allEsrVersions[1] + "%2Br"
return s
def rollupListMain(primaryVersion):
return "https://bugzilla.mozilla.org/buglist.cgi?" + \
"&f1=status_whiteboard&o1=substring&v1=adv-main" + primaryVersion + "%2Br"
def rollupListESROnly(primaryVersion, esrVersion):
return "https://bugzilla.mozilla.org/buglist.cgi?" + \
"&f2=status_whiteboard&o2=notsubstring&v2=adv-main" + primaryVersion + "%2Br" + \
"&f3=status_whiteboard&o3=substring&v3=adv-esr" + esrVersion + "%2Br"
#------------------------
def allAdvisories(version, primaryVersion, esr):
if esr:
return allAdvisoriesESR(version, primaryVersion)
else:
return allAdvisoriesMain(version)
def allAdvisoriesMain(version):
return "https://bugzilla.mozilla.org/buglist.cgi?" + \
"&f2=status_whiteboard&o2=substring&v2=adv-main" + version + "%2B"
def allAdvisoriesESR(esrVersion, primaryVersion):
return "https://bugzilla.mozilla.org/buglist.cgi?" + \
"&f2=status_whiteboard&o2=substring&v2=adv-esr" + esrVersion + "%2B"
#------------------------
def nonRollupList(version, primaryVersion, esr):
if esr:
return nonRollupListESR(version, primaryVersion)
else:
return nonRollupListMain(version)
def nonRollupListMain(version):
return "https://bugzilla.mozilla.org/buglist.cgi?" + \
"&f2=status_whiteboard&o2=substring&v2=adv-main" + version + "%2B" \
"&f3=status_whiteboard&o3=notsubstring&v3=adv-main" + version + "%2Br"
def nonRollupListESR(esrVersion, primaryVersion):
return "https://bugzilla.mozilla.org/buglist.cgi?" + \
"&f2=status_whiteboard&o2=substring&v2=adv-esr" + esrVersion + "%2B" + \
"&f3=status_whiteboard&o3=notsubstring&v3=adv-esr" + esrVersion + "%2Br"
#------------------------
def rejected(version, primaryVersion, esr):
if esr:
return rejectedESR(version, primaryVersion)
else:
return rejectedMain(version)
def rejectedMain(version):
return "https://bugzilla.mozilla.org/buglist.cgi?" + \
"&f2=status_whiteboard&o2=substring&v2=adv-main" + version + "-"
def rejectedESR(esrVersion, primaryVersion):
return "https://bugzilla.mozilla.org/buglist.cgi?" + \
"&f2=status_whiteboard&o2=substring&v2=adv-esr" + esrVersion + "-"
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Print Bugzilla queries for Security Advisories')
parser.add_argument('--verbose', '-v', action='store_true', help='Print out the extra, less-needed queries')
parser.add_argument('version', help='Version to generate queries for')
args = parser.parse_args(sys.argv[1:])
sanityCheck()
primaryVersion = args.version
versions = [primaryVersion] + versionToESRs(primaryVersion)
print("Calculating versions", versions)
for i in range(len(versions)):
version = versions[i]
print("------------------------------------------------------------")
print("Version:", version)
print("")
print("Whiteboard tags to assign:")
print(toAssign(version, primaryVersion, i != 0))
print("")
print("Advisories to write:")
print(toWrite(version, primaryVersion, i != 0))
print("")
print("Roll-up list:")
print(rollupList(version, primaryVersion, i != 0))
print("")
if not args.verbose:
continue
print("All tagged advisories:")
print(allAdvisories(version, primaryVersion, i != 0))
print("")
print("Non-rollup advisories:")
print(nonRollupList(version, primaryVersion, i != 0))
print("")
if i > 0:
print("ESR-Specific Rollups:")
print(rollupListESROnly(primaryVersion, version))
else:
print("Version-Specific Rollups:")
print(rollupListMainOnly(primaryVersion, versions[1:]))
print("")
print("Advisories considered and rejected:")
print(rejected(version, primaryVersion, i != 0))
print("")