diff mbox series

[scarthgap,v2,1/8] cve-check: decode product and vendor in CVE_STATUS

Message ID 20261201100231.3119168-2-peter.tatrai.ext@siemens.com
State New
Headers show
Series Scope global CVE exclusions by product | expand

Commit Message

P. Tatrai Dec. 1, 2026, 10:02 a.m. UTC
From: Peter Tatrai <peter.tatrai.ext@siemens.com>

CVE_STATUS entries from global includes such as cve-extra-exclusions.inc
are visible to every recipe. Master added an optional
"detail: cpe:vendor:product: description" syntax so that such entries
can name the product they apply to.

This is a partial backport of master commit
abca80a716e92fc18d3085aba1a15f4bac72379c. The parser is picked
unchanged, but under the name decode_cve_status_scoped(), and
decode_cve_status() keeps returning the (status, detail, description)
tuple it returns on scarthgap. Changing its return type, as master did,
would break existing callers in other layers on a stable branch. The
master hunks in cve-check.bbclass and spdx30_tasks.py only convert
callers to the new return type and are therefore not needed.

The parser as merged in master truncates descriptions containing ":"
and references an undefined variable in its warnings. The following
patches backport the master fixes for that.

AI-Generated: GitHub Copilot CLI, Claude Opus 5.5
Signed-off-by: Peter Tatrai <peter.tatrai.ext@siemens.com>
---
 meta/lib/oe/cve_check.py | 46 +++++++++++++++++++++++++++++++++-------
 1 file changed, 38 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/meta/lib/oe/cve_check.py b/meta/lib/oe/cve_check.py
index 7c09b78..c915ab8 100644
--- a/meta/lib/oe/cve_check.py
+++ b/meta/lib/oe/cve_check.py
@@ -225,24 +225,54 @@  def convert_cve_version(version):
 
     return version + update
 
-def decode_cve_status(d, cve):
+def decode_cve_status_scoped(d, cve):
     """
-    Convert CVE_STATUS into status, detail and description.
+    Convert CVE_STATUS into status, vendor, product, detail and description.
     """
     status = d.getVarFlag("CVE_STATUS", cve)
     if not status:
-        return ("", "", "")
+        return {}
+
+    status_split = status.split(':', 5)
+    status_out = {}
+    status_out["detail"] = status_split[0]
+    product = "*"
+    vendor = "*"
+    description = ""
+    if len(status_split) >= 4 and status_split[1].strip() == "cpe":
+        # Both vendor and product are mandatory if cpe: present, the syntax is then:
+        # detail: cpe:vendor:product:description
+        vendor = status_split[2].strip()
+        product = status_split[3].strip()
+        description = status_split[4].strip()
+    elif len(status_split) >= 2 and status_split[1].strip() == "cpe":
+        # Malformed CPE
+        bb.warn('Invalid CPE information for CVE_STATUS[%s] = "%s", not setting CPE' % (detail, cve, status))
+    else:
+        # Other case: no CPE, the syntax is then:
+        # detail: description
+        description = status_split[len(status_split)-1].strip() if (len(status_split) > 1) else ""
 
-    status_split = status.split(':', 1)
-    detail = status_split[0]
-    description = status_split[1].strip() if (len(status_split) > 1) else ""
+    status_out["vendor"] = vendor
+    status_out["product"] = product
+    status_out["description"] = description
 
-    status_mapping = d.getVarFlag("CVE_CHECK_STATUSMAP", detail)
+    status_mapping = d.getVarFlag("CVE_CHECK_STATUSMAP", status_out['detail'])
     if status_mapping is None:
         bb.warn('Invalid detail "%s" for CVE_STATUS[%s] = "%s", fallback to Unpatched' % (detail, cve, status))
         status_mapping = "Unpatched"
+    status_out["mapping"] = status_mapping
+
+    return status_out
 
-    return (status_mapping, detail, description)
+def decode_cve_status(d, cve):
+    """
+    Convert CVE_STATUS into status, detail and description.
+    """
+    status = decode_cve_status_scoped(d, cve)
+    if not status:
+        return ("", "", "")
+    return (status["mapping"], status["detail"], status["description"])
 
 def extend_cve_status(d):
     # do this only once in case multiple classes use this