Skip to content

Commit edcc77a

Browse files
fix file not found panic on windows, fix remediation steps
1 parent d9569d3 commit edcc77a

8 files changed

+8
-31
lines changed

cmd/scan/cve/CVE-2021-4104.json

-1
This file was deleted.

cmd/scan/cve/CVE-2021-44228.json

-1
This file was deleted.

cmd/scan/cve/CVE-2021-45046.json

-1
This file was deleted.

cmd/scan/cve/CVE-2021-45105.json

-1
This file was deleted.

cmd/scan/cve/libs.json

+1
Large diffs are not rendered by default.

cmd/scan/log4j.go

+5-25
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package scan
22

33
import (
4-
"embed"
54
_ "embed"
65
"encoding/json"
6+
"fmt"
77
"github.com/whitesource/log4j-detect/records"
8-
"io/fs"
9-
"path/filepath"
10-
"strings"
118
)
129

1310
type Vulnerability struct {
@@ -25,31 +22,14 @@ var fixes = map[string]map[string]string{
2522
},
2623
}
2724

28-
//go:embed cve/*.json
29-
var cveFiles embed.FS
25+
//go:embed cve/libs.json
26+
var cveFiles []byte
3027

3128
var cve2Lib []records.VulnerableLib
3229

3330
func init() {
34-
files, err := fs.ReadDir(cveFiles, "cve")
31+
err := json.Unmarshal(cveFiles, &cve2Lib)
3532
if err != nil {
36-
panic(err)
37-
}
38-
39-
for _, f := range files {
40-
var libs []records.VulnerableLib
41-
data, err := cveFiles.ReadFile(filepath.Join("cve", f.Name()))
42-
if err != nil {
43-
panic(err)
44-
}
45-
err = json.Unmarshal(data, &libs)
46-
if err != nil {
47-
panic(err)
48-
}
49-
cve := strings.ReplaceAll(f.Name(), ".json", "")
50-
for i := range libs {
51-
libs[i].CVE = cve
52-
}
53-
cve2Lib = append(cve2Lib, libs...)
33+
panic(fmt.Sprintf("failed to unmarshal libraries: %v", err))
5434
}
5535
}

cmd/scan/scan.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (o *Options) generateRemediationSteps(results []records.EnhancedResult) str
159159
for _, r := range results {
160160
for _, v := range r.DepId2VulnerableLib {
161161
if artifact2Fix, found := fixes[v.GroupId]; found {
162-
if fix, found := artifact2Fix[v.Artifact]; found {
162+
if fix, found := artifact2Fix[v.ArtifactId]; found {
163163
set[fix] = true
164164
}
165165
}

records/enhanced_result.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
type VulnerableLib struct {
1111
GroupId string `json:"groupId"`
12-
Artifact string `json:"artifact"`
12+
ArtifactId string `json:"artifactId"`
1313
PackageVersion interface{} `json:"packageVersion"`
1414
FileName string `json:"fileName"`
1515
Sha1 string `json:"sha1"`

0 commit comments

Comments
 (0)