Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ubuntu): support more versions #1368

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions gost/ubuntu.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@ type Ubuntu struct {

func (ubu Ubuntu) supported(version string) bool {
_, ok := map[string]string{
"1404": "trusty",
"1604": "xenial",
"1804": "bionic",
"2004": "focal",
"2010": "groovy",
"2104": "hirsute",
"14.04": "trusty",
"16.04": "xenial",
"18.04": "bionic",
"19.10": "eoan",
"20.04": "focal",
"20.10": "groovy",
"21.04": "hirsute",
"21.10": "impish",
}[version]
return ok
}

// DetectCVEs fills cve information that has in Gost
func (ubu Ubuntu) DetectCVEs(r *models.ScanResult, _ bool) (nCVEs int, err error) {
ubuReleaseVer := strings.Replace(r.Release, ".", "", 1)
if !ubu.supported(ubuReleaseVer) {
if !ubu.supported(r.Release) {
logging.Log.Warnf("Ubuntu %s is not supported yet", r.Release)
return 0, nil
}
Expand All @@ -54,7 +55,7 @@ func (ubu Ubuntu) DetectCVEs(r *models.ScanResult, _ bool) (nCVEs int, err error

packCvesList := []packCves{}
if ubu.DBDriver.Cnf.IsFetchViaHTTP() {
url, _ := util.URLPathJoin(ubu.DBDriver.Cnf.GetURL(), "ubuntu", ubuReleaseVer, "pkgs")
url, _ := util.URLPathJoin(ubu.DBDriver.Cnf.GetURL(), "ubuntu", r.Release, "pkgs")
responses, err := getAllUnfixedCvesViaHTTP(r, url)
if err != nil {
return 0, err
Expand All @@ -80,7 +81,7 @@ func (ubu Ubuntu) DetectCVEs(r *models.ScanResult, _ bool) (nCVEs int, err error
return 0, nil
}
for _, pack := range r.Packages {
ubuCves, err := ubu.DBDriver.DB.GetUnfixedCvesUbuntu(ubuReleaseVer, pack.Name)
ubuCves, err := ubu.DBDriver.DB.GetUnfixedCvesUbuntu(r.Release, pack.Name)
if err != nil {
return 0, nil
}
Expand All @@ -97,7 +98,7 @@ func (ubu Ubuntu) DetectCVEs(r *models.ScanResult, _ bool) (nCVEs int, err error

// SrcPack
for _, pack := range r.SrcPackages {
ubuCves, err := ubu.DBDriver.DB.GetUnfixedCvesUbuntu(ubuReleaseVer, pack.Name)
ubuCves, err := ubu.DBDriver.DB.GetUnfixedCvesUbuntu(r.Release, pack.Name)
if err != nil {
return 0, nil
}
Expand Down
26 changes: 20 additions & 6 deletions gost/ubuntu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,56 @@ func TestUbuntu_Supported(t *testing.T) {
{
name: "14.04 is supported",
args: args{
ubuReleaseVer: "1404",
ubuReleaseVer: "14.04",
},
want: true,
},
{
name: "16.04 is supported",
args: args{
ubuReleaseVer: "1604",
ubuReleaseVer: "16.04",
},
want: true,
},
{
name: "18.04 is supported",
args: args{
ubuReleaseVer: "1804",
ubuReleaseVer: "18.04",
},
want: true,
},
{
name: "19.10 is supported",
args: args{
ubuReleaseVer: "19.10",
},
want: true,
},
{
name: "20.04 is supported",
args: args{
ubuReleaseVer: "2004",
ubuReleaseVer: "20.04",
},
want: true,
},
{
name: "20.10 is supported",
args: args{
ubuReleaseVer: "2010",
ubuReleaseVer: "20.10",
},
want: true,
},
{
name: "21.04 is supported",
args: args{
ubuReleaseVer: "2104",
ubuReleaseVer: "21.04",
},
want: true,
},
{
name: "21.10 is supported",
args: args{
ubuReleaseVer: "21.10",
},
want: true,
},
Expand Down
Loading