From 6d3398574ca97cf941a67d96037d93e150536e96 Mon Sep 17 00:00:00 2001 From: Kota Kanbe Date: Tue, 6 Mar 2018 14:10:21 +0900 Subject: [PATCH] fix: support CentOS cloud image (#606) https://bugzilla.redhat.com/show_bug.cgi?id=1332025 --- report/util.go | 2 +- scan/redhat.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/report/util.go b/report/util.go index f9ee7ed1..8ef9aa53 100644 --- a/report/util.go +++ b/report/util.go @@ -378,7 +378,7 @@ func isCveInfoUpdated(cveID string, previous, current models.ScanResult) bool { } } for _, cType := range cTypes { - if equal := prevLastModified[cType].Equal(curLastModified[cType]); !equal { + if !prevLastModified[cType].Equal(curLastModified[cType]) { return true } } diff --git a/scan/redhat.go b/scan/redhat.go index 712f25dd..d6ea08ed 100644 --- a/scan/redhat.go +++ b/scan/redhat.go @@ -78,6 +78,28 @@ func detectRedhat(c config.ServerInfo) (itsMe bool, red osTypeInterface) { } } + // https://bugzilla.redhat.com/show_bug.cgi?id=1332025 + // CentOS cloud image + if r := exec(c, "ls /etc/centos-release", noSudo); r.isSuccess() { + if r := exec(c, "cat /etc/centos-release", noSudo); r.isSuccess() { + re := regexp.MustCompile(`(.*) release (\d[\d\.]*)`) + result := re.FindStringSubmatch(strings.TrimSpace(r.Stdout)) + if len(result) != 3 { + util.Log.Warn("Failed to parse CentOS version: %s", r) + return true, red + } + + release := result[2] + switch strings.ToLower(result[1]) { + case "centos", "centos linux": + red.setDistro(config.CentOS, release) + return true, red + default: + util.Log.Warn("Failed to parse CentOS: %s", r) + } + } + } + if r := exec(c, "ls /etc/redhat-release", noSudo); r.isSuccess() { // https://www.rackaid.com/blog/how-to-determine-centos-or-red-hat-version/ // e.g.