From b61adcb1fdcd92ed8efda0adf6564b7062a4ca3f Mon Sep 17 00:00:00 2001 From: Kota Kanbe Date: Mon, 7 Nov 2016 14:59:50 +0900 Subject: [PATCH] Display unknown CVEs to TUI --- models/models.go | 5 +++++ report/tui.go | 16 ++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/models/models.go b/models/models.go index c1ae27bc..165b8446 100644 --- a/models/models.go +++ b/models/models.go @@ -165,6 +165,11 @@ func (r ScanResult) CveSummary() string { high+middle+low+unknown, high, middle, low, unknown) } +// AllCves returns Known and Unknown CVEs +func (r ScanResult) AllCves() []CveInfo { + return append(r.KnownCves, r.UnknownCves...) +} + // NWLink has network link information. type NWLink struct { gorm.Model `json:"-" xml:"-"` diff --git a/report/tui.go b/report/tui.go index 2b2477d2..5e997672 100644 --- a/report/tui.go +++ b/report/tui.go @@ -222,7 +222,7 @@ func movable(v *gocui.View, nextY int) (ok bool, yLimit int) { } return true, yLimit case "summary": - yLimit = len(currentScanResult.KnownCves) - 1 + yLimit = len(currentScanResult.AllCves()) - 1 if yLimit < nextY { return false, yLimit } @@ -552,7 +552,7 @@ func setSummaryLayout(g *gocui.Gui) error { return err } - lines := summaryLines(currentScanResult) + lines := summaryLines() fmt.Fprintf(v, lines) v.Highlight = true @@ -562,21 +562,21 @@ func setSummaryLayout(g *gocui.Gui) error { return nil } -func summaryLines(data models.ScanResult) string { +func summaryLines() string { stable := uitable.New() stable.MaxColWidth = 1000 stable.Wrap = false indexFormat := "" - if len(data.KnownCves) < 10 { + if len(currentScanResult.AllCves()) < 10 { indexFormat = "[%1d]" - } else if len(data.KnownCves) < 100 { + } else if len(currentScanResult.AllCves()) < 100 { indexFormat = "[%2d]" } else { indexFormat = "[%3d]" } - for i, d := range data.KnownCves { + for i, d := range currentScanResult.AllCves() { var cols []string // packs := []string{} // for _, pack := range d.Packages { @@ -672,11 +672,11 @@ type dataForTmpl struct { } func detailLines() (string, error) { - if len(currentScanResult.KnownCves) == 0 { + if len(currentScanResult.AllCves()) == 0 { return "No vulnerable packages", nil } - cveInfo := currentScanResult.KnownCves[currentCveInfo] + cveInfo := currentScanResult.AllCves()[currentCveInfo] cveID := cveInfo.CveDetail.CveID tmpl, err := template.New("detail").Parse(detailTemplate())