Change model ScanResult.ScannedCves.AffectedPackages
This commit is contained in:
		@@ -174,12 +174,12 @@ func toSlackAttachments(r models.ScanResult) (attaches []*attachment) {
 | 
			
		||||
 | 
			
		||||
	for _, vinfo := range vinfos {
 | 
			
		||||
		curent := []string{}
 | 
			
		||||
		for _, name := range vinfo.PackageNames {
 | 
			
		||||
			if p, ok := r.Packages[name]; ok {
 | 
			
		||||
		for _, affected := range vinfo.AffectedPackages {
 | 
			
		||||
			if p, ok := r.Packages[affected.Name]; ok {
 | 
			
		||||
				curent = append(curent,
 | 
			
		||||
					fmt.Sprintf("%s-%s", p.Name, p.FormatVer()))
 | 
			
		||||
			} else {
 | 
			
		||||
				curent = append(curent, name)
 | 
			
		||||
				curent = append(curent, affected.Name)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		for _, n := range vinfo.CpeNames {
 | 
			
		||||
@@ -187,8 +187,8 @@ func toSlackAttachments(r models.ScanResult) (attaches []*attachment) {
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		new := []string{}
 | 
			
		||||
		for _, name := range vinfo.PackageNames {
 | 
			
		||||
			if p, ok := r.Packages[name]; ok {
 | 
			
		||||
		for _, affected := range vinfo.AffectedPackages {
 | 
			
		||||
			if p, ok := r.Packages[affected.Name]; ok {
 | 
			
		||||
				new = append(new, p.FormatNewVer())
 | 
			
		||||
			} else {
 | 
			
		||||
				new = append(new, "?")
 | 
			
		||||
 
 | 
			
		||||
@@ -713,8 +713,8 @@ func setChangelogLayout(g *gocui.Gui) error {
 | 
			
		||||
			lines = append(lines, adv.Format())
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		for _, name := range vinfo.PackageNames {
 | 
			
		||||
			pack := currentScanResult.Packages[name]
 | 
			
		||||
		for _, affected := range vinfo.AffectedPackages {
 | 
			
		||||
			pack := currentScanResult.Packages[affected.Name]
 | 
			
		||||
			for _, p := range currentScanResult.Packages {
 | 
			
		||||
				if pack.Name == p.Name {
 | 
			
		||||
					lines = append(lines, p.FormatChangelog(), "\n")
 | 
			
		||||
@@ -763,10 +763,10 @@ func detailLines() (string, error) {
 | 
			
		||||
	vinfo := vinfos[currentVinfo]
 | 
			
		||||
 | 
			
		||||
	packsVer := []string{}
 | 
			
		||||
	sort.Strings(vinfo.PackageNames)
 | 
			
		||||
	for _, name := range vinfo.PackageNames {
 | 
			
		||||
	vinfo.AffectedPackages.Sort()
 | 
			
		||||
	for _, affected := range vinfo.AffectedPackages {
 | 
			
		||||
		// packages detected by OVAL may not be actually installed
 | 
			
		||||
		if pack, ok := r.Packages[name]; ok {
 | 
			
		||||
		if pack, ok := r.Packages[affected.Name]; ok {
 | 
			
		||||
			packsVer = append(packsVer, pack.FormatVersionFromTo())
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -216,9 +216,9 @@ No CVE-IDs are found in updatable packages.
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		packsVer := []string{}
 | 
			
		||||
		sort.Strings(vuln.PackageNames)
 | 
			
		||||
		for _, name := range vuln.PackageNames {
 | 
			
		||||
			if pack, ok := r.Packages[name]; ok {
 | 
			
		||||
		vuln.AffectedPackages.Sort()
 | 
			
		||||
		for _, affected := range vuln.AffectedPackages {
 | 
			
		||||
			if pack, ok := r.Packages[affected.Name]; ok {
 | 
			
		||||
				packsVer = append(packsVer, pack.FormatVersionFromTo())
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
@@ -322,9 +322,9 @@ func diff(curResults, preResults models.ScanResults) (diffed models.ScanResults,
 | 
			
		||||
			current.ScannedCves = getDiffCves(previous, current)
 | 
			
		||||
			packages := models.Packages{}
 | 
			
		||||
			for _, s := range current.ScannedCves {
 | 
			
		||||
				for _, name := range s.PackageNames {
 | 
			
		||||
					p := current.Packages[name]
 | 
			
		||||
					packages[name] = p
 | 
			
		||||
				for _, affected := range s.AffectedPackages {
 | 
			
		||||
					p := current.Packages[affected.Name]
 | 
			
		||||
					packages[affected.Name] = p
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			current.Packages = packages
 | 
			
		||||
 
 | 
			
		||||
@@ -183,13 +183,13 @@ func TestDiff(t *testing.T) {
 | 
			
		||||
					ScannedCves: models.VulnInfos{
 | 
			
		||||
						"CVE-2012-6702": {
 | 
			
		||||
							CveID:            "CVE-2012-6702",
 | 
			
		||||
							PackageNames:     []string{"libexpat1"},
 | 
			
		||||
							AffectedPackages: models.PackageStatuses{{Name: "libexpat1"}},
 | 
			
		||||
							DistroAdvisories: []models.DistroAdvisory{},
 | 
			
		||||
							CpeNames:         []string{},
 | 
			
		||||
						},
 | 
			
		||||
						"CVE-2014-9761": {
 | 
			
		||||
							CveID:            "CVE-2014-9761",
 | 
			
		||||
							PackageNames:     []string{"libc-bin"},
 | 
			
		||||
							AffectedPackages: models.PackageStatuses{{Name: "libc-bin"}},
 | 
			
		||||
							DistroAdvisories: []models.DistroAdvisory{},
 | 
			
		||||
							CpeNames:         []string{},
 | 
			
		||||
						},
 | 
			
		||||
@@ -208,13 +208,13 @@ func TestDiff(t *testing.T) {
 | 
			
		||||
					ScannedCves: models.VulnInfos{
 | 
			
		||||
						"CVE-2012-6702": {
 | 
			
		||||
							CveID:            "CVE-2012-6702",
 | 
			
		||||
							PackageNames:     []string{"libexpat1"},
 | 
			
		||||
							AffectedPackages: models.PackageStatuses{{Name: "libexpat1"}},
 | 
			
		||||
							DistroAdvisories: []models.DistroAdvisory{},
 | 
			
		||||
							CpeNames:         []string{},
 | 
			
		||||
						},
 | 
			
		||||
						"CVE-2014-9761": {
 | 
			
		||||
							CveID:            "CVE-2014-9761",
 | 
			
		||||
							PackageNames:     []string{"libc-bin"},
 | 
			
		||||
							AffectedPackages: models.PackageStatuses{{Name: "libc-bin"}},
 | 
			
		||||
							DistroAdvisories: []models.DistroAdvisory{},
 | 
			
		||||
							CpeNames:         []string{},
 | 
			
		||||
						},
 | 
			
		||||
@@ -245,7 +245,7 @@ func TestDiff(t *testing.T) {
 | 
			
		||||
					ScannedCves: models.VulnInfos{
 | 
			
		||||
						"CVE-2016-6662": {
 | 
			
		||||
							CveID:            "CVE-2016-6662",
 | 
			
		||||
							PackageNames:     []string{"mysql-libs"},
 | 
			
		||||
							AffectedPackages: models.PackageStatuses{{Name: "mysql-libs"}},
 | 
			
		||||
							DistroAdvisories: []models.DistroAdvisory{},
 | 
			
		||||
							CpeNames:         []string{},
 | 
			
		||||
						},
 | 
			
		||||
@@ -283,7 +283,7 @@ func TestDiff(t *testing.T) {
 | 
			
		||||
				ScannedCves: models.VulnInfos{
 | 
			
		||||
					"CVE-2016-6662": {
 | 
			
		||||
						CveID:            "CVE-2016-6662",
 | 
			
		||||
						PackageNames:     []string{"mysql-libs"},
 | 
			
		||||
						AffectedPackages: models.PackageStatuses{{Name: "mysql-libs"}},
 | 
			
		||||
						DistroAdvisories: []models.DistroAdvisory{},
 | 
			
		||||
						CpeNames:         []string{},
 | 
			
		||||
					},
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user