Change structure of ScanResult.[]VulnInfo to Map

This commit is contained in:
Kota Kanbe
2017-05-09 21:03:54 +09:00
committed by kota kanbe
parent b977558f38
commit cfb848918f
12 changed files with 129 additions and 224 deletions

View File

@@ -62,10 +62,9 @@ func (o Debian) FillCveInfoFromOvalDB(r *models.ScanResult) error {
func (o Debian) fillOvalInfo(r *models.ScanResult, definition *ovalmodels.Definition) {
ovalContent := *o.convertToModel(definition)
ovalContent.Type = models.NewCveContentType(r.Family)
vinfo, ok := r.ScannedCves.Get(definition.Debian.CveID)
vinfo, ok := r.ScannedCves[definition.Debian.CveID]
if !ok {
util.Log.Infof("%s is newly detected by OVAL",
definition.Debian.CveID)
util.Log.Infof("%s is newly detected by OVAL", definition.Debian.CveID)
vinfo = models.VulnInfo{
CveID: definition.Debian.CveID,
Confidence: models.OvalMatch,
@@ -73,17 +72,20 @@ func (o Debian) fillOvalInfo(r *models.ScanResult, definition *ovalmodels.Defini
CveContents: models.NewCveContents(ovalContent),
}
} else {
if _, ok := vinfo.CveContents.Get(models.NewCveContentType(r.Family)); !ok {
util.Log.Infof("%s is also detected by OVAL", definition.Debian.CveID)
} else {
cveContents := vinfo.CveContents
if _, ok := vinfo.CveContents.Get(models.NewCveContentType(r.Family)); 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)
cveContents = models.CveContents{}
}
if vinfo.Confidence.Score < models.OvalMatch.Score {
vinfo.Confidence = models.OvalMatch
}
vinfo.CveContents.Upsert(ovalContent)
cveContents.Upsert(ovalContent)
vinfo.CveContents = cveContents
}
r.ScannedCves.Upsert(vinfo)
r.ScannedCves[definition.Debian.CveID] = vinfo
}
func (o Debian) convertToModel(def *ovalmodels.Definition) *models.CveContent {

View File

@@ -59,7 +59,7 @@ func (o Redhat) FillCveInfoFromOvalDB(r *models.ScanResult) error {
func (o Redhat) fillOvalInfo(r *models.ScanResult, definition *ovalmodels.Definition) {
for _, cve := range definition.Advisory.Cves {
ovalContent := *o.convertToModel(cve.CveID, definition)
vinfo, ok := r.ScannedCves.Get(cve.CveID)
vinfo, ok := r.ScannedCves[cve.CveID]
if !ok {
util.Log.Infof("%s is newly detected by OVAL", cve.CveID)
vinfo = models.VulnInfo{
@@ -69,17 +69,21 @@ func (o Redhat) fillOvalInfo(r *models.ScanResult, definition *ovalmodels.Defini
CveContents: models.NewCveContents(ovalContent),
}
} else {
if _, ok := vinfo.CveContents.Get(models.RedHat); !ok {
util.Log.Infof("%s is also detected by OVAL", cve.CveID)
} else {
cveContents := vinfo.CveContents
if _, ok := vinfo.CveContents.Get(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)
cveContents = models.CveContents{}
}
if vinfo.Confidence.Score < models.OvalMatch.Score {
vinfo.Confidence = models.OvalMatch
}
vinfo.CveContents.Upsert(ovalContent)
cveContents.Upsert(ovalContent)
vinfo.CveContents = cveContents
}
r.ScannedCves.Upsert(vinfo)
r.ScannedCves[cve.CveID] = vinfo
}
}