diff --git a/commands/report.go b/commands/report.go index 76a0bae5..96223beb 100644 --- a/commands/report.go +++ b/commands/report.go @@ -513,7 +513,7 @@ func fillCveDetail(r *models.ScanResult) error { } for _, con := range []models.CveContent{*nvd, *jvn} { if !con.Empty() { - vinfo.CveContents.Upsert(con) + vinfo.CveContents[con.Type] = con } } r.ScannedCves[cveID] = vinfo diff --git a/commands/util.go b/commands/util.go index 97bf0464..73d73001 100644 --- a/commands/util.go +++ b/commands/util.go @@ -239,7 +239,7 @@ func isCveInfoUpdated(cveID string, previous, current models.ScanResult) bool { for _, c := range previous.ScannedCves { if cveID == c.CveID { for _, cType := range cTypes { - content, _ := c.CveContents.Get(cType) + content, _ := c.CveContents[cType] prevLastModified[cType] = content.LastModified } break @@ -250,7 +250,7 @@ func isCveInfoUpdated(cveID string, previous, current models.ScanResult) bool { for _, c := range current.ScannedCves { if cveID == c.CveID { for _, cType := range cTypes { - content, _ := c.CveContents.Get(cType) + content, _ := c.CveContents[cType] curLastModified[cType] = content.LastModified } break diff --git a/models/models.go b/models/models.go index 5efc7028..4030475f 100644 --- a/models/models.go +++ b/models/models.go @@ -412,50 +412,14 @@ func NewCveContents(conts ...CveContent) CveContents { return m } -// Get CveContent by cveID -// TODO Pointer -func (v CveContents) Get(typestr CveContentType) (CveContent, bool) { - if vv, ok := v[typestr]; ok { - return vv, true - } - return CveContent{}, false -} - -// Delete by cveID -func (v CveContents) Delete(typestr CveContentType) { - delete(v, typestr) -} - -// Insert CveContent -func (v CveContents) Insert(cont CveContent) { - v[cont.Type] = cont -} - -// Update VulnInfo -func (v CveContents) Update(cont CveContent) (ok bool) { - if _, ok := v[cont.Type]; ok { - v[cont.Type] = cont - return true - } - return false -} - -// Upsert CveContent -func (v CveContents) Upsert(cont CveContent) { - ok := v.Update(cont) - if !ok { - v.Insert(cont) - } -} - // CvssV2Score returns CVSS V2 Score func (v CveContents) CvssV2Score() float64 { //TODO - if cont, found := v.Get(NVD); found { + if cont, found := v[NVD]; found { return cont.Cvss2Score - } else if cont, found := v.Get(JVN); found { + } else if cont, found := v[JVN]; found { return cont.Cvss2Score - } else if cont, found := v.Get(RedHat); found { + } else if cont, found := v[RedHat]; found { return cont.Cvss2Score } return -1.1 @@ -463,7 +427,7 @@ func (v CveContents) CvssV2Score() float64 { // CvssV3Score returns CVSS V2 Score func (v CveContents) CvssV3Score() float64 { - if cont, found := v.Get(RedHat); found { + if cont, found := v[RedHat]; found { return cont.Cvss3Score } return -1.1 diff --git a/oval/debian.go b/oval/debian.go index d8384afd..ac108d9d 100644 --- a/oval/debian.go +++ b/oval/debian.go @@ -73,7 +73,8 @@ func (o Debian) fillOvalInfo(r *models.ScanResult, definition *ovalmodels.Defini } } else { cveContents := vinfo.CveContents - if _, ok := vinfo.CveContents.Get(models.NewCveContentType(r.Family)); ok { + ctype := models.NewCveContentType(r.Family) + if _, ok := vinfo.CveContents[ctype]; ok { util.Log.Infof("%s will be updated by OVAL", definition.Debian.CveID) } else { util.Log.Infof("%s is also detected by OVAL", definition.Debian.CveID) @@ -82,7 +83,7 @@ func (o Debian) fillOvalInfo(r *models.ScanResult, definition *ovalmodels.Defini if vinfo.Confidence.Score < models.OvalMatch.Score { vinfo.Confidence = models.OvalMatch } - cveContents.Upsert(ovalContent) + cveContents[ctype] = ovalContent vinfo.CveContents = cveContents } r.ScannedCves[definition.Debian.CveID] = vinfo diff --git a/oval/redhat.go b/oval/redhat.go index 980c4f85..009324c9 100644 --- a/oval/redhat.go +++ b/oval/redhat.go @@ -70,7 +70,7 @@ func (o Redhat) fillOvalInfo(r *models.ScanResult, definition *ovalmodels.Defini } } else { cveContents := vinfo.CveContents - if _, ok := vinfo.CveContents.Get(models.RedHat); ok { + if _, ok := vinfo.CveContents[models.RedHat]; ok { util.Log.Infof("%s will be updated by OVAL", cve.CveID) } else { util.Log.Infof("%s is also detected by OVAL", cve.CveID) @@ -80,7 +80,7 @@ func (o Redhat) fillOvalInfo(r *models.ScanResult, definition *ovalmodels.Defini if vinfo.Confidence.Score < models.OvalMatch.Score { vinfo.Confidence = models.OvalMatch } - cveContents.Upsert(ovalContent) + cveContents[models.RedHat] = ovalContent vinfo.CveContents = cveContents } r.ScannedCves[cve.CveID] = vinfo