@@ -18,7 +18,6 @@ import (
18
18
"cmp"
19
19
"encoding/json"
20
20
"errors"
21
- "fmt"
22
21
"io"
23
22
"net/url"
24
23
"os"
@@ -224,41 +223,43 @@ func (v *Vulnerability) AddPkgInfo(pkgInfo PackageInfo) {
224
223
}
225
224
}
226
225
226
+ // Aggregate commits by their repo, and synthesize a zero introduced commit if necessary.
227
227
if len (pkgInfo .VersionInfo .AffectedCommits ) > 0 {
228
228
gitCommitRangesByRepo := map [string ]AffectedRange {}
229
229
230
230
hasAddedZeroIntroduced := make (map [string ]bool )
231
231
232
232
for _ , ac := range pkgInfo .VersionInfo .AffectedCommits {
233
233
entry , ok := gitCommitRangesByRepo [ac .Repo ]
234
+ // Create the stub for the repo if necessary.
234
235
if ! ok {
235
236
entry = AffectedRange {
236
237
Type : "GIT" ,
237
238
Events : []Event {},
238
239
Repo : ac .Repo ,
239
240
}
240
- }
241
241
242
- if ! pkgInfo .VersionInfo .HasIntroducedCommits (ac .Repo ) && ! hasAddedZeroIntroduced [ac .Repo ] {
243
- // There was no explicitly defined introduced commit, so create one at 0
244
- entry .Events = append (entry .Events ,
245
- Event {
246
- Introduced : "0" ,
247
- },
248
- )
249
- hasAddedZeroIntroduced [ac .Repo ] = true
242
+ if ! pkgInfo .VersionInfo .HasIntroducedCommits (ac .Repo ) && ! hasAddedZeroIntroduced [ac .Repo ] {
243
+ // There was no explicitly defined introduced commit, so create one at 0.
244
+ entry .Events = append (entry .Events ,
245
+ Event {
246
+ Introduced : "0" ,
247
+ },
248
+ )
249
+ hasAddedZeroIntroduced [ac .Repo ] = true
250
+ }
250
251
}
251
252
252
- if pkgInfo . VersionInfo . HasIntroducedCommits ( ac .Repo ) {
253
+ if ac .Introduced != "" {
253
254
entry .Events = append (entry .Events , Event {Introduced : ac .Introduced })
254
255
}
255
- if pkgInfo . VersionInfo . HasFixedCommits ( ac .Repo ) {
256
+ if ac .Fixed != "" {
256
257
entry .Events = append (entry .Events , Event {Fixed : ac .Fixed })
257
258
}
258
- if pkgInfo . VersionInfo . HasLastAffectedCommits ( ac .Repo ) {
259
+ if ac .LastAffected != "" {
259
260
entry .Events = append (entry .Events , Event {LastAffected : ac .LastAffected })
260
261
}
261
- if pkgInfo . VersionInfo . HasLimitCommits ( ac .Repo ) {
262
+ if ac .Limit != "" {
262
263
entry .Events = append (entry .Events , Event {Limit : ac .Limit })
263
264
}
264
265
gitCommitRangesByRepo [ac .Repo ] = entry
@@ -599,18 +600,9 @@ func FromCVE(id cves.CVEID, cve cves.CVE) (*Vulnerability, []string) {
599
600
Details : cves .EnglishDescription (cve ),
600
601
Aliases : extractAliases (id , cve ),
601
602
}
602
- var err error
603
603
var notes []string
604
604
v .Published = cve .Published .Format (time .RFC3339 )
605
- if err != nil {
606
- notes = append (notes , fmt .Sprintf ("Failed to parse published date: %v\n " , err ))
607
- }
608
-
609
605
v .Modified = cve .LastModified .Format (time .RFC3339 )
610
- if err != nil {
611
- notes = append (notes , fmt .Sprintf ("Failed to parse modified date: %v\n " , err ))
612
- }
613
-
614
606
v .References = ClassifyReferences (cve .References )
615
607
v .AddSeverity (cve .Metrics )
616
608
return & v , notes
0 commit comments