@@ -125,19 +125,19 @@ func AddVersionInfo(cve cves.CVE5, v *vulns.Vulnerability, metrics *ConversionMe
125
125
126
126
v .Affected = append (v .Affected , aff )
127
127
if hasGit {
128
- metrics .VersionSources = append ( metrics . VersionSources , VersionSourceGit )
128
+ metrics .AddSource ( VersionSourceGit )
129
129
} else {
130
- metrics .VersionSources = append ( metrics . VersionSources , VersionSourceAffected )
130
+ metrics .AddSource ( VersionSourceAffected )
131
131
}
132
132
}
133
133
134
134
// If no versions were found so far, fall back to CPEs.
135
135
if ! gotVersions {
136
- metrics .Notes = append ( metrics . Notes , "No versions in affected, attempting to extract from CPE" )
136
+ metrics .AddNote ( "No versions in affected, attempting to extract from CPE" )
137
137
cpeRanges , cpeStrings , err := findCPEVersionRanges (cve )
138
138
if err == nil && len (cpeRanges ) > 0 {
139
139
gotVersions = true
140
- metrics .VersionSources = append ( metrics . VersionSources , VersionSourceCPE )
140
+ metrics .AddSource ( VersionSourceCPE )
141
141
aff := osvschema.Affected {}
142
142
for _ , vr := range cpeRanges {
143
143
vr .Type = osvschema .RangeEcosystem
@@ -147,19 +147,21 @@ func AddVersionInfo(cve cves.CVE5, v *vulns.Vulnerability, metrics *ConversionMe
147
147
aff .DatabaseSpecific ["CPEs" ] = vulns .Unique (cpeStrings )
148
148
v .Affected = append (v .Affected , aff )
149
149
} else if err != nil {
150
- metrics .Notes = append ( metrics . Notes , err .Error ())
150
+ metrics .AddNote ( "%s" , err .Error ())
151
151
}
152
152
}
153
153
154
154
// As a last resort, try extracting versions from the description text.
155
155
if ! gotVersions {
156
- metrics .Notes = append ( metrics . Notes , "No versions in CPEs so attempting extraction from description" )
156
+ metrics .AddNote ( "No versions in CPEs so attempting extraction from description" )
157
157
versions , extractNotes := cves .ExtractVersionsFromText (nil , cves .EnglishDescription (cve .Containers .CNA .Descriptions ))
158
- metrics .Notes = append (metrics .Notes , extractNotes ... )
158
+ for _ , note := range extractNotes {
159
+ metrics .AddNote ("%s" , note )
160
+ }
159
161
if len (versions ) > 0 {
160
162
// NOTE: These versions are not currently saved due to the need for better validation.
161
- metrics .VersionSources = append ( metrics . VersionSources , VersionSourceDescription )
162
- metrics .Notes = append ( metrics . Notes , fmt . Sprintf ( "Extracted versions from description but did not save them: %+v" , versions ) )
163
+ metrics .AddSource ( VersionSourceDescription )
164
+ metrics .AddNote ( "Extracted versions from description but did not save them: %+v" , versions )
163
165
}
164
166
}
165
167
}
@@ -225,7 +227,7 @@ func extractVersionsFromAffectedField(affected cves.Affected, cnaAssigner string
225
227
// It sorts the introduced and fixed versions to create chronological ranges.
226
228
func findInverseAffectedRanges (cveAff cves.Affected , cnaAssigner string , metrics * ConversionMetrics ) (ranges []osvschema.Range , versType VersionRangeType ) {
227
229
if cnaAssigner != "Linux" {
228
- metrics .Notes = append ( metrics . Notes , "Currently only supporting Linux inverse logic" )
230
+ metrics .AddNote ( "Currently only supporting Linux inverse logic" )
229
231
return nil , VersionRangeTypeUnknown
230
232
}
231
233
var introduced []string
@@ -240,7 +242,7 @@ func findInverseAffectedRanges(cveAff cves.Affected, cnaAssigner string, metrics
240
242
case 3 :
241
243
introduced = append (introduced , versionValue )
242
244
default :
243
- metrics .Notes = append ( metrics . Notes , "Bad non-semver version given: " + versionValue )
245
+ metrics .AddNote ( "Bad non-semver version given: %s" , versionValue )
244
246
continue
245
247
}
246
248
}
@@ -275,15 +277,15 @@ func findInverseAffectedRanges(cveAff cves.Affected, cnaAssigner string, metrics
275
277
for index , f := range fixed {
276
278
if index < len (introduced ) {
277
279
ranges = append (ranges , buildVersionRange (introduced [index ], "" , f ))
278
- metrics .Notes = append ( metrics . Notes , "Introduced from version value - " + introduced [index ])
279
- metrics .Notes = append ( metrics . Notes , "Fixed from version value - " + f )
280
+ metrics .AddNote ( "Introduced from version value - %s" , introduced [index ])
281
+ metrics .AddNote ( "Fixed from version value - %s" , f )
280
282
}
281
283
}
282
284
283
285
if len (ranges ) != 0 {
284
286
return ranges , VersionRangeTypeSemver
285
287
}
286
- metrics .Notes = append ( metrics . Notes , "no ranges found" )
288
+ metrics .AddNote ( "no ranges found" )
287
289
288
290
return nil , VersionRangeTypeUnknown
289
291
}
@@ -304,30 +306,30 @@ func findNormalAffectedRanges(affected cves.Affected, metrics *ConversionMetrics
304
306
// Quality check the version strings to avoid using filler content.
305
307
vQuality := vulns .CheckQuality (vers .Version )
306
308
if ! vQuality .AtLeast (acceptableQuality ) {
307
- metrics .Notes = append ( metrics . Notes , fmt . Sprintf ( "Version value for %s %s is filler or empty" , affected .Vendor , affected .Product ) )
309
+ metrics .AddNote ( "Version value for %s %s is filler or empty" , affected .Vendor , affected .Product )
308
310
}
309
311
vLessThanQual := vulns .CheckQuality (vers .LessThan )
310
312
vLTOEQual := vulns .CheckQuality (vers .LessThanOrEqual )
311
313
312
314
hasRange := vLessThanQual .AtLeast (acceptableQuality ) || vLTOEQual .AtLeast (acceptableQuality )
313
- metrics .Notes = append ( metrics . Notes , fmt . Sprintf ( "Range detected: %v" , hasRange ) )
315
+ metrics .AddNote ( "Range detected: %v" , hasRange )
314
316
// Handle cases where 'lessThan' is mistakenly the same as 'version'.
315
317
if vers .LessThan != "" && vers .LessThan == vers .Version {
316
- metrics .Notes = append ( metrics . Notes , fmt . Sprintf ( "Warning: lessThan (%s) is the same as introduced (%s)\n " , vers .LessThan , vers .Version ) )
318
+ metrics .AddNote ( "Warning: lessThan (%s) is the same as introduced (%s)\n " , vers .LessThan , vers .Version )
317
319
hasRange = false
318
320
}
319
321
320
322
if hasRange {
321
323
if vQuality .AtLeast (acceptableQuality ) {
322
324
introduced = vers .Version
323
- metrics .Notes = append ( metrics . Notes , fmt . Sprintf ( "%s - Introduced from version value - %s" , vQuality .String (), vers .Version ) )
325
+ metrics .AddNote ( "%s - Introduced from version value - %s" , vQuality .String (), vers .Version )
324
326
}
325
327
if vLessThanQual .AtLeast (acceptableQuality ) {
326
328
fixed = vers .LessThan
327
- metrics .Notes = append ( metrics . Notes , fmt . Sprintf ( "%s - Fixed from LessThan value - %s" , vLessThanQual .String (), vers .LessThan ) )
329
+ metrics .AddNote ( "%s - Fixed from LessThan value - %s" , vLessThanQual .String (), vers .LessThan )
328
330
} else if vLTOEQual .AtLeast (acceptableQuality ) {
329
331
lastaffected = vers .LessThanOrEqual
330
- metrics .Notes = append ( metrics . Notes , fmt . Sprintf ( "%s - LastAffected from LessThanOrEqual value- %s" , vLTOEQual .String (), vers .LessThanOrEqual ) )
332
+ metrics .AddNote ( "%s - LastAffected from LessThanOrEqual value- %s" , vLTOEQual .String (), vers .LessThanOrEqual )
331
333
}
332
334
333
335
if introduced != "" && fixed != "" {
@@ -342,7 +344,7 @@ func findNormalAffectedRanges(affected cves.Affected, metrics *ConversionMetrics
342
344
// In this case only vers.Version exists which either means that it is _only_ that version that is
343
345
// affected, but more likely, it affects up to that version. It could also mean that the range is given
344
346
// in one line instead - like "< 1.5.3" or "< 2.45.4, >= 2.0 " or just "before 1.4.7", so check for that.
345
- metrics .Notes = append ( metrics . Notes , "Only version exists" )
347
+ metrics .AddNote ( "Only version exists" )
346
348
// GitHub often encodes the range directly in the version string.
347
349
348
350
av , err := git .ParseVersionRange (vers .Version )
@@ -365,12 +367,14 @@ func findNormalAffectedRanges(affected cves.Affected, metrics *ConversionMetrics
365
367
}
366
368
367
369
// Try to extract versions from text like "before 1.4.7".
368
- possibleVersions , note := cves .ExtractVersionsFromText (nil , vers .Version )
369
- if note != nil {
370
- metrics .Notes = append (metrics .Notes , note ... )
370
+ possibleVersions , notes := cves .ExtractVersionsFromText (nil , vers .Version )
371
+
372
+ for _ , note := range notes {
373
+ metrics .AddNote ("%s" , note )
371
374
}
375
+
372
376
if possibleVersions != nil {
373
- metrics .Notes = append ( metrics . Notes , "Versions retrieved from text but not used CURRENTLY" )
377
+ metrics .AddNote ( "Versions retrieved from text but not used CURRENTLY" )
374
378
continue
375
379
}
376
380
0 commit comments