Skip to content

Commit

Permalink
fix: index out of range while downloading vulnerability database
Browse files Browse the repository at this point in the history
  • Loading branch information
gnmahanth committed May 10, 2023
1 parent 270d622 commit fecf360
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
9 changes: 8 additions & 1 deletion deepfence_server/handler/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,17 @@ func downloadVulnerabilityDb() {
return
}

log.Info().Msgf("available vulnerability databases V3=%d V5=%d",
len(listing.Available[model.Version3]), len(listing.Available[model.Version5]))

// sort by built time
listing.Sort(model.Version5)
// listing.Sort(model.Version5)

latest := listing.Latest(model.Version5)
if latest == nil {
log.Error().Msgf("latest v5 database are empty, check listing url")
return
}

log.Info().Msgf("latest threat intel db: %v", latest)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,28 @@ func (v *VulnerabilityDBListing) Append(db Database, version string) {
}

func (v *VulnerabilityDBListing) Sort(version string) {
v5db := v.Available[version]
if len(v.Available[version]) <= 1 {
return
}

sort.Slice(v5db[:], func(i, j int) bool {
return v5db[i].Built.Before(v5db[j].Built)
dbs := v.Available[version]
sort.Slice(dbs[:], func(i, j int) bool {
return dbs[i].Built.Before(dbs[j].Built)
})

v.Available[version] = v5db
v.Available[version] = dbs
}

func (v *VulnerabilityDBListing) Latest(version string) *Database {
// sort, get last element
v.Sort(version)

dbs, ok := v.Available[version]
if !ok {
return nil

}
return &dbs[len(dbs)-1]
if len(dbs) >= 1 {
return &dbs[len(dbs)-1]
}
return nil
}

0 comments on commit fecf360

Please sign in to comment.