Skip to content

Commit b94f157

Browse files
fix: skip UNK-* and Re cves (#383)
Co-authored-by: Copilot <[email protected]>
1 parent 3dee684 commit b94f157

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

photon/photon.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,22 @@ func (c Config) Update() error {
8787
return nil
8888
}
8989

90-
func (c Config) saveCVEPerPkg(dirName, pkgName, cveID string, data interface{}) error {
90+
func (c Config) saveCVEPerPkg(dirName, pkgName, cveID string, cve PhotonCVE) error {
9191
if cveID == "" {
9292
log.Printf("CVE-ID is empty")
9393
return nil
9494
}
9595

96+
// Only skip unknown CVE entries (IDs starting with "UNK-" or "Re") that lack version information.
97+
// Valid CVEs (e.g., "CVE-...") with both ResVer and AffVer as "NA" are still saved,
98+
// as their status (e.g., "Not Affected") may be meaningful for reporting.
99+
if (strings.HasPrefix(cveID, "UNK-") || cveID == "Re") &&
100+
(cve.ResVer == "" || cve.ResVer == "NA") &&
101+
(cve.AffVer == "" || cve.AffVer == "NA") {
102+
log.Printf("Skip unknown CVE entry: %s", cveID)
103+
return nil
104+
}
105+
96106
s := strings.Split(cveID, "-")
97107
if len(s) != 3 {
98108
log.Printf("invalid CVE-ID: %s", cveID)
@@ -101,7 +111,7 @@ func (c Config) saveCVEPerPkg(dirName, pkgName, cveID string, data interface{})
101111

102112
pkgDir := filepath.Join(c.VulnListDir, dirName, pkgName)
103113
fileName := fmt.Sprintf("%s.json", cveID)
104-
if err := utils.WriteJSON(c.AppFs, pkgDir, fileName, data); err != nil {
114+
if err := utils.WriteJSON(c.AppFs, pkgDir, fileName, cve); err != nil {
105115
return xerrors.Errorf("failed to write file: %w", err)
106116
}
107117
return nil

photon/photon_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func TestConfig_Update(t *testing.T) {
4949
"/tmp/photon/3.0/apache-tomcat/CVE-2019-0199.json": "testdata/golden/CVE-2019-0199.json",
5050
"/tmp/photon/3.0/apache-tomcat/CVE-2019-10072.json": "testdata/golden/CVE-2019-10072.json",
5151
"/tmp/photon/3.0/binutils/CVE-2017-16826.json": "testdata/golden/CVE-2017-16826.json",
52+
"/tmp/photon/3.0/curl/CVE-2025-0725.json": "testdata/golden/CVE-2025-0725.json",
5253
},
5354
},
5455
{
@@ -127,6 +128,7 @@ func TestConfig_Update(t *testing.T) {
127128
"/tmp/photon/3.0/apache-tomcat/CVE-2019-0199.json": "testdata/golden/CVE-2019-0199.json",
128129
"/tmp/photon/3.0/apache-tomcat/CVE-2019-10072.json": "testdata/golden/CVE-2019-10072.json",
129130
"/tmp/photon/3.0/binutils/CVE-2017-16826.json": "testdata/golden/CVE-2017-16826.json",
131+
"/tmp/photon/3.0/curl/CVE-2025-0725.json": "testdata/golden/CVE-2025-0725.json",
130132
},
131133
},
132134
}

photon/testdata/cve_data_photon3.0.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,21 @@
2626
"cve_score": 7.8,
2727
"aff_ver": "all versions before 2.31.1-3.ph3 are vulnerable",
2828
"res_ver": "2.31.1-3.ph3"
29+
},
30+
{
31+
"cve_id": "UNK-1",
32+
"pkg": "curl-libs",
33+
"cve_score": 6.7,
34+
"aff_ver": "NA",
35+
"res_ver": "NA",
36+
"status": "Not Affected"
37+
},
38+
{
39+
"cve_id": "CVE-2025-0725",
40+
"pkg": "curl",
41+
"cve_score": 7.3,
42+
"aff_ver": "NA",
43+
"res_ver": "NA",
44+
"status": "Not Affected"
2945
}
3046
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"os_version": "3.0",
3+
"cve_id": "CVE-2025-0725",
4+
"pkg": "curl",
5+
"cve_score": 7.3,
6+
"aff_ver": "NA",
7+
"res_ver": "NA"
8+
}

0 commit comments

Comments
 (0)