diff --git a/models/vulninfos.go b/models/vulninfos.go index 13813ea1..195a5f05 100644 --- a/models/vulninfos.go +++ b/models/vulninfos.go @@ -162,22 +162,29 @@ func (v VulnInfo) VendorLinks(family string) map[string]string { return links } -// TODO // NilToEmpty set nil slice or map fields to empty to avoid null in JSON -// func (v *VulnInfo) NilToEmpty() { -// if v.CpeNames == nil { -// v.CpeNames = []string{} -// } -// if v.DistroAdvisories == nil { -// v.DistroAdvisories = []DistroAdvisory{} -// } -// if v.PackageNames == nil { -// v.PackageNames = []string{} -// } -// if v.CveContents == nil { -// v.CveContents = NewCveContents() -// } -// } +func (v *VulnInfo) NilToEmpty() *VulnInfo { + if v.CpeNames == nil { + v.CpeNames = []string{} + } + if v.DistroAdvisories == nil { + v.DistroAdvisories = []DistroAdvisory{} + } + if v.PackageNames == nil { + v.PackageNames = []string{} + } + if v.CveContents == nil { + v.CveContents = NewCveContents() + } + for key := range v.CveContents { + if v.CveContents[key].Cpes == nil { + cont := v.CveContents[key] + cont.Cpes = []Cpe{} + v.CveContents[key] = cont + } + } + return v +} // DistroAdvisory has Amazon Linux, RHEL, FreeBSD Security Advisory information. type DistroAdvisory struct { diff --git a/report/report.go b/report/report.go index 7cdefdf9..c63397a1 100644 --- a/report/report.go +++ b/report/report.go @@ -104,6 +104,11 @@ func fillCveInfo(r *models.ScanResult) error { if err := fillCveInfoFromCveDB(r); err != nil { return fmt.Errorf("Failed to fill CVE information: %s", err) } + + for cveID := range r.ScannedCves { + vinfo := r.ScannedCves[cveID] + r.ScannedCves[cveID] = *vinfo.NilToEmpty() + } return nil } @@ -192,8 +197,6 @@ func fillVulnByCpeNames(cpeNames []string, scannedVulns models.VulnInfos) error CpeNames: []string{name}, Confidence: models.CpeNameMatch, } - //TODO - // v.NilToEmpty() scannedVulns[detail.CveID] = v } }