Skip to content

Commit

Permalink
fix: lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
holyspectral committed Dec 9, 2024
1 parent 3cd5dbd commit 1349f6c
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 58 deletions.
22 changes: 11 additions & 11 deletions common/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ type dbSpace struct {

var DBS dbSpace = dbSpace{
Buffers: [DBMax]dbBuffer{
DBUbuntu: dbBuffer{Name: "ubuntu"},
DBDebian: dbBuffer{Name: "debian"},
DBCentos: dbBuffer{Name: "centos"},
DBAlpine: dbBuffer{Name: "alpine"},
DBAmazon: dbBuffer{Name: "amazon"},
DBOracle: dbBuffer{Name: "oracle"},
DBMariner: dbBuffer{Name: "mariner"},
DBPhoton: dbBuffer{Name: "photon"},
DBSuse: dbBuffer{Name: "suse"},
DBRocky: dbBuffer{Name: "rocky"},
DBUbuntu: {Name: "ubuntu"},
DBDebian: {Name: "debian"},
DBCentos: {Name: "centos"},
DBAlpine: {Name: "alpine"},
DBAmazon: {Name: "amazon"},
DBOracle: {Name: "oracle"},
DBMariner: {Name: "mariner"},
DBPhoton: {Name: "photon"},
DBSuse: {Name: "suse"},
DBRocky: {Name: "rocky"},
},
}

Expand Down Expand Up @@ -492,7 +492,7 @@ func LoadAppVulsTb(path string) (map[string][]AppModuleVul, error) {
// org.apache.logging.log4j.log4j-core: for backward compatibility
// log4j-core: for jar file without pom.xml. Prefix jar: to avoid collision
var mns []string
for mn, _ := range vul {
for mn := range vul {
if colon := strings.LastIndex(mn, ":"); colon > 0 {
mns = append(mns, mn)
}
Expand Down
48 changes: 24 additions & 24 deletions cvetools/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@ type versionTestCase struct {

func TestAffectedVersion(t *testing.T) {
cases := []versionTestCase{
versionTestCase{result: false, version: "1.2.3", dbVer: []common.AppModuleVersion{}},
versionTestCase{result: true, version: "1.2.3", dbVer: []common.AppModuleVersion{common.AppModuleVersion{OpCode: "lt", Version: "1.2.4"}}},
versionTestCase{result: false, version: "1.2.4", dbVer: []common.AppModuleVersion{common.AppModuleVersion{OpCode: "lt", Version: "1.2.4"}}},
versionTestCase{result: true, version: "4.0.1", dbVer: []common.AppModuleVersion{common.AppModuleVersion{OpCode: "", Version: "4.0.1"}}},
versionTestCase{result: true, version: "1.2.3", dbVer: []common.AppModuleVersion{common.AppModuleVersion{OpCode: "lt", Version: "1.2.4"}, {OpCode: "gt", Version: "1.2.0"}}},
versionTestCase{result: true, version: "1.3.4", dbVer: []common.AppModuleVersion{common.AppModuleVersion{OpCode: "lt", Version: "1.2.4"}, {OpCode: "gt", Version: "1.2.0"}, {OpCode: "orlt", Version: "1.3.5"}}},
versionTestCase{result: true, version: "1.3.4", dbVer: []common.AppModuleVersion{common.AppModuleVersion{OpCode: "lt", Version: "1.2.4"}, {OpCode: "gt", Version: "1.2.0"}, {OpCode: "lt", Version: "1.3.5"}}},
versionTestCase{result: false, version: "1.3.4", dbVer: []common.AppModuleVersion{common.AppModuleVersion{OpCode: "lt", Version: "1.2.4"}, {OpCode: "lt", Version: "1.3.5"}}},
versionTestCase{result: true, version: "1.3.4", dbVer: []common.AppModuleVersion{common.AppModuleVersion{OpCode: "lt", Version: "1.2.4"}, {OpCode: "orlt", Version: "1.3.5"}}},
versionTestCase{result: true, version: "1.3.4", dbVer: []common.AppModuleVersion{common.AppModuleVersion{OpCode: "lt", Version: "1.2.4"}, {OpCode: "orlt", Version: "1.3.5"}, {OpCode: "gteq", Version: "1.3.4"}}},
versionTestCase{result: false, version: "1.3.3", dbVer: []common.AppModuleVersion{common.AppModuleVersion{OpCode: "lt", Version: "1.2.4"}, {OpCode: "orlt", Version: "1.3.5"}, {OpCode: "gteq", Version: "1.3.4"}}},
versionTestCase{result: true, version: "1.1.1", dbVer: []common.AppModuleVersion{common.AppModuleVersion{OpCode: "lt", Version: "1.2.4"}}},
versionTestCase{result: false, version: "1.1.1", dbVer: []common.AppModuleVersion{common.AppModuleVersion{OpCode: "lt", Version: "1.2.4,1.2"}}},
versionTestCase{result: true, version: "1.3.6", dbVer: []common.AppModuleVersion{common.AppModuleVersion{OpCode: "lt", Version: "1.2.4"}, {OpCode: "lt", Version: "1.3.7"}, {OpCode: "gt", Version: "1.3.5"}}},
versionTestCase{result: true, version: "1.3.6", dbVer: []common.AppModuleVersion{common.AppModuleVersion{OpCode: "lt", Version: "1.2.4"}, {OpCode: "orlt", Version: "1.3.7"}, {OpCode: "gt", Version: "1.3.5"}}},
versionTestCase{result: false, version: "2.9.1-6.el7.4", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "2.9.1-6.el7_2.2"}}},
versionTestCase{result: false, version: "4.18.0-193.19.1.el8_2", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "4.18.0-193.19.1.el8"}}},
versionTestCase{result: false, version: "4.18.0-193.19.1.el8_2", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "4.18.0-193.el8"}}},
versionTestCase{result: true, version: "4.18.0-193.19.1.el8", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "4.18.0-193.19.1.el8_2"}}},
versionTestCase{result: false, version: "4.18.0.el8_2", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "4.18.0.el8"}}},
versionTestCase{result: false, version: "5.2.4.5", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "5.2.4.3,5.2"}, {OpCode: "orlt", Version: "6.0.3.1"}}},
versionTestCase{result: true, version: "5.2.4.5", dbVer: []common.AppModuleVersion{{OpCode: "gteq", Version: "5.2.4.3,5.2"}, {OpCode: "orgteq", Version: "6.0.3.1"}}},
versionTestCase{result: false, version: "5.0.11", dbVer: []common.AppModuleVersion{{OpCode: "gteq", Version: "5.0"}, {OpCode: "lteq", Version: "5.0.8"}, {OpCode: "orgteq", Version: "2.1"}, {OpCode: "lteq", Version: "2.1.28"}, {OpCode: "orgteq", Version: "3.1"}, {OpCode: "lteq", Version: "3.1.17"}, {OpCode: "orgteq", Version: "7.0"}, {OpCode: "lt", Version: "7.0.7"}, {OpCode: "orgteq", Version: "7.1"}, {OpCode: "lt", Version: "7.1.4"}}},
{result: false, version: "1.2.3", dbVer: []common.AppModuleVersion{}},
{result: true, version: "1.2.3", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "1.2.4"}}},
{result: false, version: "1.2.4", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "1.2.4"}}},
{result: true, version: "4.0.1", dbVer: []common.AppModuleVersion{{OpCode: "", Version: "4.0.1"}}},
{result: true, version: "1.2.3", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "1.2.4"}, {OpCode: "gt", Version: "1.2.0"}}},
{result: true, version: "1.3.4", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "1.2.4"}, {OpCode: "gt", Version: "1.2.0"}, {OpCode: "orlt", Version: "1.3.5"}}},
{result: true, version: "1.3.4", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "1.2.4"}, {OpCode: "gt", Version: "1.2.0"}, {OpCode: "lt", Version: "1.3.5"}}},
{result: false, version: "1.3.4", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "1.2.4"}, {OpCode: "lt", Version: "1.3.5"}}},
{result: true, version: "1.3.4", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "1.2.4"}, {OpCode: "orlt", Version: "1.3.5"}}},
{result: true, version: "1.3.4", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "1.2.4"}, {OpCode: "orlt", Version: "1.3.5"}, {OpCode: "gteq", Version: "1.3.4"}}},
{result: false, version: "1.3.3", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "1.2.4"}, {OpCode: "orlt", Version: "1.3.5"}, {OpCode: "gteq", Version: "1.3.4"}}},
{result: true, version: "1.1.1", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "1.2.4"}}},
{result: false, version: "1.1.1", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "1.2.4,1.2"}}},
{result: true, version: "1.3.6", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "1.2.4"}, {OpCode: "lt", Version: "1.3.7"}, {OpCode: "gt", Version: "1.3.5"}}},
{result: true, version: "1.3.6", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "1.2.4"}, {OpCode: "orlt", Version: "1.3.7"}, {OpCode: "gt", Version: "1.3.5"}}},
{result: false, version: "2.9.1-6.el7.4", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "2.9.1-6.el7_2.2"}}},
{result: false, version: "4.18.0-193.19.1.el8_2", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "4.18.0-193.19.1.el8"}}},
{result: false, version: "4.18.0-193.19.1.el8_2", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "4.18.0-193.el8"}}},
{result: true, version: "4.18.0-193.19.1.el8", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "4.18.0-193.19.1.el8_2"}}},
{result: false, version: "4.18.0.el8_2", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "4.18.0.el8"}}},
{result: false, version: "5.2.4.5", dbVer: []common.AppModuleVersion{{OpCode: "lt", Version: "5.2.4.3,5.2"}, {OpCode: "orlt", Version: "6.0.3.1"}}},
{result: true, version: "5.2.4.5", dbVer: []common.AppModuleVersion{{OpCode: "gteq", Version: "5.2.4.3,5.2"}, {OpCode: "orgteq", Version: "6.0.3.1"}}},
{result: false, version: "5.0.11", dbVer: []common.AppModuleVersion{{OpCode: "gteq", Version: "5.0"}, {OpCode: "lteq", Version: "5.0.8"}, {OpCode: "orgteq", Version: "2.1"}, {OpCode: "lteq", Version: "2.1.28"}, {OpCode: "orgteq", Version: "3.1"}, {OpCode: "lteq", Version: "3.1.17"}, {OpCode: "orgteq", Version: "7.0"}, {OpCode: "lt", Version: "7.0.7"}, {OpCode: "orgteq", Version: "7.1"}, {OpCode: "lt", Version: "7.1.4"}}},
}

for _, c := range cases {
Expand All @@ -54,7 +54,7 @@ func TestAffectedVersion(t *testing.T) {

func TestFixedVersion(t *testing.T) {
cases := []versionTestCase{
versionTestCase{result: true, version: "4.0.2", dbVer: []common.AppModuleVersion{{OpCode: "gteq", Version: "2.12.5"}, {OpCode: "lt", Version: "3.0.0"}, {OpCode: "orgteq", Version: "3.7.2"}, {OpCode: "lt", Version: "4.0.0"}, {OpCode: "orgteq", Version: "4.0.0.beta8"}}},
{result: true, version: "4.0.2", dbVer: []common.AppModuleVersion{{OpCode: "gteq", Version: "2.12.5"}, {OpCode: "lt", Version: "3.0.0"}, {OpCode: "orgteq", Version: "3.7.2"}, {OpCode: "lt", Version: "4.0.0"}, {OpCode: "orgteq", Version: "4.0.0.beta8"}}},
}
for _, c := range cases {
v, _ := utils.NewVersion(c.version)
Expand Down
6 changes: 3 additions & 3 deletions cvetools/cvesearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func (cv *ScanTools) ScanImage(ctx context.Context, req *share.ScanImageRequest,
// remove the opaque directories/files from lower layers
for _, dir := range removed[layers[i]] {
// log.WithFields(log.Fields{"dir": dir, "layerID": layers[i]}).Debug("Remove")
for fpath, _ := range fileMap {
for fpath := range fileMap {
if strings.HasPrefix(fpath, dir) {
delete(fileMap, fpath)
}
Expand Down Expand Up @@ -553,7 +553,7 @@ func (cv *ScanTools) ScanImage(ctx context.Context, req *share.ScanImageRequest,
isBase := baseLayers.Contains(l)
if lf, ok := layerFiles[l]; ok {
var hasRpmPackages bool
for filename, _ := range lf.Pkgs {
for filename := range lf.Pkgs {
if scan.RPMPkgFiles.Contains(filename) {
hasRpmPackages = true
break
Expand Down Expand Up @@ -1309,7 +1309,7 @@ func makeFeatureMap(vss []common.VulShort, namespace string) map[string][]common
Namespace: v.Namespace,
Fixin: []common.FeaShort{
// make a copy instead of reference
common.FeaShort{Name: ft.Name, Version: ft.Version, MinVer: ft.MinVer},
{Name: ft.Name, Version: ft.Version, MinVer: ft.MinVer},
},
CPEs: v.CPEs,
}
Expand Down
32 changes: 16 additions & 16 deletions cvetools/cvetools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ func TestSelectDB(t *testing.T) {
}

tests := map[string]result{
"alpine:3.4.6": result{"alpine:3.4", common.DBAlpine},
"rhel:8.3": result{"centos:8", common.DBCentos},
"mariner:1.0": result{"mariner:1.0", common.DBMariner},
"opensuse-leap:15.2": result{"sles:l15.2", common.DBSuse},
"ol:7.8.2": result{"oracle:7", common.DBOracle},
"ubuntu:7.1": result{"ubuntu:7.1", common.DBUbuntu},
"debian:3.1": result{"debian:3.1", common.DBDebian},
"server:5.4": result{"centos:5", common.DBCentos},
"centos:5.4": result{"centos:5", common.DBCentos},
"amzn:1.8": result{"amzn:1", common.DBAmazon},
"sles:2.7": result{"sles:2.7", common.DBSuse},
"opensuse-leap:2.7": result{"sles:l2.7", common.DBSuse},
"alpine:3.4.6": {"alpine:3.4", common.DBAlpine},
"rhel:8.3": {"centos:8", common.DBCentos},
"mariner:1.0": {"mariner:1.0", common.DBMariner},
"opensuse-leap:15.2": {"sles:l15.2", common.DBSuse},
"ol:7.8.2": {"oracle:7", common.DBOracle},
"ubuntu:7.1": {"ubuntu:7.1", common.DBUbuntu},
"debian:3.1": {"debian:3.1", common.DBDebian},
"server:5.4": {"centos:5", common.DBCentos},
"centos:5.4": {"centos:5", common.DBCentos},
"amzn:1.8": {"amzn:1", common.DBAmazon},
"sles:2.7": {"sles:2.7", common.DBSuse},
"opensuse-leap:2.7": {"sles:l2.7", common.DBSuse},
}

for os, r := range tests {
Expand Down Expand Up @@ -85,11 +85,11 @@ func TestEpochComparison(t *testing.T) {
nsWithEpoch := "rhel:8"
verString := "0:1.5"
shortVulMap := map[string][]common.VulShort{
"rhel:8:test": []common.VulShort{common.VulShort{
"rhel:8:test": {{
Name: "CVE-1",
Namespace: "rhel:8",
Fixin: []common.FeaShort{
common.FeaShort{
{
Name: "test",
Version: "1:1.0",
MinVer: "",
Expand All @@ -98,11 +98,11 @@ func TestEpochComparison(t *testing.T) {
CPEs: []string{},
},
},
"amzn:2023:test": []common.VulShort{common.VulShort{
"amzn:2023:test": {{
Name: "CVE-1",
Namespace: "amzn:2023",
Fixin: []common.FeaShort{
common.FeaShort{
{
Name: "test",
Version: "1:1.0",
MinVer: "",
Expand Down
2 changes: 1 addition & 1 deletion cvetools/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ func collectLayerRawRecord(imgPath string, downloads []string) (map[string][]sha
lmap := make(map[string]string)
if _, rFiles, err := collectImageFileMap(fpath, lmap); err == nil {
files := make([]string, 0)
for f, _ := range lmap {
for f := range lmap {
files = append(files, f)
}
fmap[id] = files
Expand Down
2 changes: 1 addition & 1 deletion cvetools/scan_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (lc *ImageLayerCacher) pruneRecordCache(name string, cacher *CacherData, ke

// exclude current cached layers, pick 8-16 victims
var keys []string
for key, _ := range cacher.CacheRecordMap {
for key := range cacher.CacheRecordMap {
if keepers.Contains(key) {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion cvetools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func collectImageFileMap(rootPath string, fmap map[string]string) (int, []string

// (1) remove the opaque directories from lower layers
for _, dir := range opqDirs {
for path, _ := range fmap {
for path := range fmap {
if strings.HasPrefix(path, dir) {
// log.WithFields(log.Fields{"path": path, "dir": dir}).Info("Remove")
delete(fmap, path)
Expand Down
2 changes: 1 addition & 1 deletion detectors/osrelease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"`

data := map[string]*FeatureFile{
"etc/os-release": &FeatureFile{Data: []byte(osr)},
"etc/os-release": {Data: []byte(osr)},
}

ns := detectOSRelease(data)
Expand Down

0 comments on commit 1349f6c

Please sign in to comment.