Skip to contentSkip to conversation

testing/tests/utils/test_generate_cyclonedx.py: test scp-style git sites

PATCH Applied Thomas Perale via buildroot 1 participant 32 messages Jun 24 – Oct 16

lore
Share & tools
lore
#0 lore raw

PATCH 1/9 testing/tests/utils/test_generate_cyclonedx.py: test scp-style git sites

The commit [1] fixed a formatting bug with the SCP style git sites declaration.

Add this style of link to the test case to keep a track of it.

[1] ebcfdb8b0a utils/generate-cyclonedx: fixup scp-style git sites

---
 support/testing/tests/utils/test_generate_cyclonedx.py | 6 ++++++
 1 file changed, 6 insertions(+)
support/testing/tests/utils/test_generate_cyclonedx.py +6 -0
index e6640fbd0d..b91add2349 100644
@@ -149,6 +149,7 @@ class TestGenerateCycloneDX(unittest.TestCase):
                 "uris": [
                     "git+git://git.example.org/foo",
                     "svn+https://svn.example.org/foo",
+                    "[email protected]:project/foo.git",
                     "https+https://sources.buildroot.net/foo",
                     "http|https+https://mirror.example.org/foo",
                 ],
@@ -172,6 +173,11 @@ class TestGenerateCycloneDX(unittest.TestCase):
                     "url": "https://svn.example.org/foo",
                     "comment": "svn repository",
                 },
+                {
+                    "type": "vcs",
+                    "url": "ssh://[email protected]/project/foo.git",
+                    "comment": "git repository",
+                },
                 {
                     "type": "source-distribution",
                     "url": "https://mirror.example.org/foo/foo-1.2.tar.gz",
Signature · 6 lines
2.54.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

PATCH 2/9 utils/generate-cyclonedx: make urllib.error import explicit

Commit [1] introduced a code block that reference 'urllib.error.URLError'. There is not explicit import to 'urllib.error'. While this is not an issue in practice, linter complains that the import is not explicit.

[1] 17c9deb115 utils/generate-cyclonedx: hint at missing Buildroot host package on a specific error

---
 utils/generate-cyclonedx | 1 +
 1 file changed, 1 insertion(+)
utils/generate-cyclonedx +1 -0
index df12ee84c0..e337770599 100755
@@ -16,6 +16,7 @@ from pathlib import Path
 from typing import Iterator
 import urllib.parse
 import urllib.request
+import urllib.error
 import subprocess
 import sys
 import re
Signature · 6 lines
2.54.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
author Reviewed-by Quentin Schulz on v1 2/9
#2 lore raw

Re: [Buildroot] [PATCH 2/9] utils/generate-cyclonedx: make urllib.error import explicit

Hi Thomas,

Quoted 7 lines · Thomas Perale

Commit [1] introduced a code block that reference 'urllib.error.URLError'. There is not explicit import to 'urllib.error'. While this is not an issue in practice, linter complains that the import is not explicit.

[1] 17c9deb115 utils/generate-cyclonedx: hint at missing Buildroot host package on a specific error

Thanks!
Quentin
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#3 lore raw

Re: [Buildroot] [PATCH 2/9] utils/generate-cyclonedx: make urllib.error import explicit

In reply to Thomas Perale via buildroot
Quoted 17 lines · Thomas Perale via buildroot

Commit [1] introduced a code block that reference 'urllib.error.URLError'. There is not explicit import to 'urllib.error'. While this is not an issue in practice, linter complains that the import is not explicit.

[1] 17c9deb115 utils/generate-cyclonedx: hint at missing Buildroot host package on a specific error

---
  utils/generate-cyclonedx | 1 +
  1 file changed, 1 insertion(+)
utils/generate-cyclonedx +0 -0
index df12ee84c0..e337770599 100755

utils/generate-cyclonedx from pathlib import Path · line 19

Quoted 4 lines
utils/generate-cyclonedx +1 -0
@@ -16,6 +16,7 @@ from pathlib import Path
  from typing import Iterator
  import urllib.parse
  import urllib.request
+import urllib.error

We're not consistent but ideally we keep the imports alphabetically sorted.

Regards,
Arnout

utils/generate-cyclonedx from pathlib import Path · line 22

Quoted 3 lines
utils/generate-cyclonedx +0 -0
  import subprocess
  import sys
  import re

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#4 lore raw

Re: [Buildroot] [PATCH 2/9] utils/generate-cyclonedx: make urllib.error import explicit

In reply to Thomas Perale via buildroot

In reply of:

Quoted 9 lines

Commit [1] introduced a code block that reference 'urllib.error.URLError'. There is not explicit import to 'urllib.error'. While this is not an issue in practice, linter complains that the import is not explicit.

[1] 17c9deb115 utils/generate-cyclonedx: hint at missing Buildroot host package on a specific error

Applied to 2025.02.x, 2026.08.x. Thanks

Quoted 9 lines
---
 utils/generate-cyclonedx | 1 +
 1 file changed, 1 insertion(+)
utils/generate-cyclonedx +0 -0
index df12ee84c0..e337770599 100755

utils/generate-cyclonedx from pathlib import Path · line 22

Quoted 7 lines
utils/generate-cyclonedx +1 -0
@@ -16,6 +16,7 @@ from pathlib import Path
 from typing import Iterator
 import urllib.parse
 import urllib.request
+import urllib.error
 import subprocess
 import sys
 import re

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#5 lore raw

PATCH 3/9 utils/generate-cyclonedx: add 'id' property to resolves

In reply to Thomas Perale via buildroot

The CycloneDX spec defines the components.pedigree.patches.resolves object [1] as supporting both a 'name' & 'id' property.

The definition provided for the id property is the following [2]:

Quoted 1 line

The identifier of the issue assigned by the source of the issue

And for the name property [3]:

Quoted 1 line

The name of the issue

The resolves object was introduced in commit [4] and only used the name property to link to the vulnerability it resolves.

In example [5] provided on the CycloneDX website, both the name & id properties are set in the security example.

In the vulnerability context, and more precisely the CVEs, the name and the `id' are the same and thus the value can be duplicated across the two properties.

This commit replicates the behavior documented in [5] to improve compatibility with tools.

[1] https://cyclonedx.org/docs/1.6/json/#components_items_pedigree_patches_items_resolves
[2] https://cyclonedx.org/docs/1.6/json/#components_items_pedigree_patches_items_resolves_items_id
[3] https://cyclonedx.org/docs/1.6/json/#components_items_pedigree_patches_items_resolves_items_name
[4] 9415529923 utils/generate-cyclonedx: add support for 'resolved_with_pedigree'
[5] https://cyclonedx.org/use-cases/pedigree/

---
 utils/generate-cyclonedx | 1 +
 1 file changed, 1 insertion(+)
utils/generate-cyclonedx +1 -0
index e337770599..902b4276ec 100755
@@ -233,6 +233,7 @@ def cyclonedx_patches(patch_list: list[str]):
                     "resolves": [
                         {
                             "type": "security",
+                            "id": cve,
                             "name": cve
                         } for cve in cves
                     ]
Signature · 6 lines
2.54.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
author Reviewed-by Quentin Schulz on v1 3/9
#6 lore raw

Re: [Buildroot] [PATCH 3/9] utils/generate-cyclonedx: add 'id' property to resolves

Hi Thomas,

Quoted 21 lines · Thomas Perale

The CycloneDX spec defines the components.pedigree.patches.resolves object [1] as supporting both a 'name' & 'id' property.

The definition provided for the id property is the following [2]:

Quoted 1 line

The identifier of the issue assigned by the source of the issue

And for the name property [3]:

Quoted 1 line

The name of the issue

The resolves object was introduced in commit [4] and only used the name property to link to the vulnerability it resolves.

In example [5] provided on the CycloneDX website, both the name & id properties are set in the security example.

In the vulnerability context, and more precisely the CVEs, the name and the `id' are the same and thus the value can be duplicated across the two properties.

Quoted 9 lines

This commit replicates the behavior documented in [5] to improve compatibility with tools.

[1] https://cyclonedx.org/docs/1.6/json/#components_items_pedigree_patches_items_resolves
[2] https://cyclonedx.org/docs/1.6/json/#components_items_pedigree_patches_items_resolves_items_id
[3] https://cyclonedx.org/docs/1.6/json/#components_items_pedigree_patches_items_resolves_items_name
[4] 9415529923 utils/generate-cyclonedx: add support for 'resolved_with_pedigree'
[5] https://cyclonedx.org/use-cases/pedigree/

Thanks!
Quentin
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#7 lore raw

Re: [Buildroot] [PATCH 3/9] utils/generate-cyclonedx: add 'id' property to resolves

In reply to Thomas Perale via buildroot

In reply of:

Quoted 24 lines

The CycloneDX spec defines the components.pedigree.patches.resolves object [1] as supporting both a 'name' & 'id' property.

The definition provided for the id property is the following [2]:

Quoted 1 line

The identifier of the issue assigned by the source of the issue

And for the name property [3]:

Quoted 1 line

The name of the issue

The resolves object was introduced in commit [4] and only used the name property to link to the vulnerability it resolves.

In example [5] provided on the CycloneDX website, both the name & id properties are set in the security example.

In the vulnerability context, and more precisely the CVEs, the name and the `id' are the same and thus the value can be duplicated across the two properties.

This commit replicates the behavior documented in [5] to improve compatibility with tools.

Quoted 8 lines

[1] https://cyclonedx.org/docs/1.6/json/#components_items_pedigree_patches_items_resolves
[2] https://cyclonedx.org/docs/1.6/json/#components_items_pedigree_patches_items_resolves_items_id
[3] https://cyclonedx.org/docs/1.6/json/#components_items_pedigree_patches_items_resolves_items_name
[4] 9415529923 utils/generate-cyclonedx: add support for 'resolved_with_pedigree'
[5] https://cyclonedx.org/use-cases/pedigree/

Applied to 2025.02.x, 2026.08.x. Thanks

Quoted 9 lines
---
 utils/generate-cyclonedx | 1 +
 1 file changed, 1 insertion(+)
utils/generate-cyclonedx +0 -0
index e337770599..902b4276ec 100755

utils/generate-cyclonedx def cyclonedx_patches(patch_list: list[str]): · line 239

Quoted 7 lines
utils/generate-cyclonedx +1 -0
@@ -233,6 +233,7 @@ def cyclonedx_patches(patch_list: list[str]):
                     "resolves": [
                         {
                             "type": "security",
+                            "id": cve,
                             "name": cve
                         } for cve in cves
                     ]

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#8 lore raw

PATCH 4/9 utils/generate-cyclonedx: mark host packages as excluded

In reply to Thomas Perale via buildroot

Mark Buildroot's host packages as 'excluded' with the scope property [1]. The excluded scope is defined like the following:

Quoted 3 lines

Components that are excluded provide the ability to document component usage for test and other non-runtime purposes. Excluded components are not reachable within a call graph at runtime.

This fits the usage of 'host' packages : a package without a runtime purpose.

See the mailing list discussion around this property [2][3][4][5]

[1] https://cyclonedx.org/docs/1.6/json/#metadata_tools_oneOf_i0_components_items_scope
[2] https://lore.kernel.org/r/<[email protected]>
[3] https://lore.kernel.org/r/<[email protected]>
[4] https://lore.kernel.org/r/<[email protected]>
[5] https://lore.kernel.org/r/<[email protected]>

---
 utils/generate-cyclonedx | 3 +++
 1 file changed, 3 insertions(+)
utils/generate-cyclonedx +3 -0
index 902b4276ec..9e3bc9d4b8 100755
@@ -371,6 +371,9 @@ def cyclonedx_component(name, comp):
     return {
         "bom-ref": name,
         "type": "library",
+        **({
+            "scope": "excluded"
+        } if comp["type"] == "host" else {}),
         **({
             "name": comp["name"],
         } if "name" in comp else {}),
Signature · 6 lines
2.54.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
author Reviewed-by Quentin Schulz on v1 4/9
#9 lore raw

Re: [Buildroot] [PATCH 4/9] utils/generate-cyclonedx: mark host packages as excluded

Hi Thomas,

Quoted 10 lines · Thomas Perale

Mark Buildroot's host packages as 'excluded' with the scope property [1]. The excluded scope is defined like the following:

Quoted 3 lines

Components that are excluded provide the ability to document component usage for test and other non-runtime purposes. Excluded components are not reachable within a call graph at runtime.

This fits the usage of 'host' packages : a package without a runtime purpose.

Quoted 8 lines

See the mailing list discussion around this property [2][3][4][5]

[1] https://cyclonedx.org/docs/1.6/json/#metadata_tools_oneOf_i0_components_items_scope
[2] https://lore.kernel.org/r/<[email protected]>
[3] https://lore.kernel.org/r/<[email protected]>
[4] https://lore.kernel.org/r/<[email protected]>
[5] https://lore.kernel.org/r/<[email protected]>

I was wondering if the toolchain (which brings a libc for example) would be impacted by this, but no, so this here is likely fine.

Quoted 10 lines
---
  utils/generate-cyclonedx | 3 +++
  1 file changed, 3 insertions(+)
utils/generate-cyclonedx +0 -0
index 902b4276ec..9e3bc9d4b8 100755

utils/generate-cyclonedx def cyclonedx_component(name, comp): · line 376

Quoted 6 lines
utils/generate-cyclonedx +3 -0
@@ -371,6 +371,9 @@ def cyclonedx_component(name, comp):
      return {
          "bom-ref": name,
          "type": "library",
+        **({
+            "scope": "excluded"
+        } if comp["type"] == "host" else {}),

The spec says there can be three states here, excluded, required and optional, the default being required. I'm assuming with the example of the toolchain above, we may not want to make all target packages "required" (explicitly, that is, though that is essentially the same as not setting it). But maybe we can filter packages we know cannot be called on the target (e.g. a toolchain, but then, can we have a toolchain in the final image, such that we can compile on the target for e.g. another device?).

This seems fine to me for host packages in any case, so

Thanks!
Quentin
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#10 lore raw

Re: [Buildroot] [PATCH 4/9] utils/generate-cyclonedx: mark host packages as excluded

In reply to Thomas Perale via buildroot

In reply of:

Quoted 12 lines

Mark Buildroot's host packages as 'excluded' with the scope property [1]. The excluded scope is defined like the following:

Quoted 3 lines

Components that are excluded provide the ability to document component usage for test and other non-runtime purposes. Excluded components are not reachable within a call graph at runtime.

This fits the usage of 'host' packages : a package without a runtime purpose.

See the mailing list discussion around this property [2][3][4][5]

Quoted 8 lines

[1] https://cyclonedx.org/docs/1.6/json/#metadata_tools_oneOf_i0_components_items_scope
[2] https://lore.kernel.org/r/<[email protected]>
[3] https://lore.kernel.org/r/<[email protected]>
[4] https://lore.kernel.org/r/<[email protected]>
[5] https://lore.kernel.org/r/<[email protected]>

Applied to 2025.02.x, 2026.08.x. Thanks

Quoted 9 lines
---
 utils/generate-cyclonedx | 3 +++
 1 file changed, 3 insertions(+)
utils/generate-cyclonedx +0 -0
index 902b4276ec..9e3bc9d4b8 100755

utils/generate-cyclonedx def cyclonedx_component(name, comp): · line 379

Quoted 9 lines
utils/generate-cyclonedx +3 -0
@@ -371,6 +371,9 @@ def cyclonedx_component(name, comp):
     return {
         "bom-ref": name,
         "type": "library",
+        **({
+            "scope": "excluded"
+        } if comp["type"] == "host" else {}),
         **({
             "name": comp["name"],
         } if "name" in comp else {}),

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#11 lore raw

PATCH 5/9 utils/generate-cyclonedx: move license download in a function

In reply to Thomas Perale via buildroot

Move the code that retrieve the SPDX licenses into a function instead of doing it top-level.

This allows to pass the CycloneDX version as a function argument instead of defining it as a top-level constant.
The next commit, introduce support for different CycloneDX spec version.

---
 utils/generate-cyclonedx | 60 ++++++++++++++++++++++++++--------------
 1 file changed, 39 insertions(+), 21 deletions(-)
utils/generate-cyclonedx +39 -21
index 9e3bc9d4b8..9738db71d6 100755
@@ -23,12 +23,10 @@ import re
 
 
 CYCLONEDX_VERSION = "1.6"
-SPDX_SCHEMA_URL = f"https://raw.githubusercontent.com/CycloneDX/specification/{CYCLONEDX_VERSION}/schema/spdx.schema.json"
 
 brpath = Path(__file__).parent.parent
 
 cyclonedxpath = Path(os.getenv("BR2_DL_DIR", brpath / "dl")) / "cyclonedx"
-SPDX_SCHEMA_PATH = cyclonedxpath / f"spdx-{CYCLONEDX_VERSION}.schema.json"
 
 BR2_VERSION_FULL = (
     subprocess.check_output(
@@ -45,28 +43,47 @@ VULN_WITH_PEDIGREE = set()
 
 SPDX_LICENSES = []
 
-if not SPDX_SCHEMA_PATH.exists():
-    if not importlib.util.find_spec("_ssl"):
-        print(f"ssl module required for downloading {SPDX_SCHEMA_URL}. Try enabling BR2_PACKAGE_HOST_PYTHON3_SSL.",
-              file=sys.stderr)
-        exit(1)
 
-    # Download the CycloneDX SPDX schema JSON, and cache it locally
-    cyclonedxpath.mkdir(parents=True, exist_ok=True)
+def br2_retrieve_spdx_licenses(version: str):
+    """Populate the list of supported SPDX licenses for a given CycloneDX
+    version. If the list is not present locally it will be downloaded
+    externally.
+
+    Args:
+        version (str): CycloneDX version
+
+    Returns:
+        The SPDX license list supported for the argument version.
+    """
+    SPDX_SCHEMA_URL = f"https://raw.githubusercontent.com/CycloneDX/specification/{version}/schema/spdx.schema.json"
+
+    ret = []
+    path = cyclonedxpath / f"spdx-{version}.schema.json"
+
+    if not path.exists():
+        # Download the CycloneDX SPDX schema JSON, and cache it locally
+        if not importlib.util.find_spec("_ssl"):
+            print(f"ssl module required for downloading {SPDX_SCHEMA_URL}. Try enabling BR2_PACKAGE_HOST_PYTHON3_SSL.",
+                  file=sys.stderr)
+            exit(1)
+
+        cyclonedxpath.mkdir(parents=True, exist_ok=True)
+        try:
+            urllib.request.urlretrieve(SPDX_SCHEMA_URL, path)
+        except urllib.error.URLError as e:
+            if "CERTIFICATE_VERIFY_FAILED" in str(e.reason):
+                raise Exception("Couldn't verify certificate. Try enabling BR2_PACKAGE_HOST_CA_CERTIFICATES.")
+            raise e
+
     try:
-        urllib.request.urlretrieve(SPDX_SCHEMA_URL, SPDX_SCHEMA_PATH)
-    except urllib.error.URLError as e:
-        if "CERTIFICATE_VERIFY_FAILED" in str(e.reason):
-            raise Exception("Couldn't verify certificate. Try enabling BR2_PACKAGE_HOST_CA_CERTIFICATES.")
-        raise e
+        with path.open() as f:
+            ret = json.load(f).get("enum", [])
+    except json.JSONDecodeError:
+        # In case of error the license will just not be matched to the SPDX names
+        # but the SBOM generation still work.
+        print(f"Failed to load the SPDX licenses file: {path}", file=sys.stderr)
 
-try:
-    with SPDX_SCHEMA_PATH.open() as f:
-        SPDX_LICENSES = json.load(f).get("enum", [])
-except json.JSONDecodeError:
-    # In case of error the license will just not be matched to the SPDX names
-    # but the SBOM generation still work.
-    print(f"Failed to load the SPDX licenses file: {SPDX_SCHEMA_PATH}", file=sys.stderr)
+    return ret
 
 
 def split_top_level_comma(subj):
@@ -528,6 +545,7 @@ def main():
         parser.print_help()
         sys.exit(1)
 
+    SPDX_LICENSES.extend(br2_retrieve_spdx_licenses(CYCLONEDX_VERSION))
     show_info_dict = json.load(args.in_file)
 
     # Remove rootfs and virtual packages if not explicitly included
Signature · 6 lines
2.54.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
author Reviewed-by Quentin Schulz on v1 5/9
#12 lore raw

Re: [Buildroot] [PATCH 5/9] utils/generate-cyclonedx: move license download in a function

Hi Thomas,

Quoted 7 lines · Thomas Perale

Move the code that retrieve the SPDX licenses into a function instead of doing it top-level.

This allows to pass the CycloneDX version as a function argument instead of defining it as a top-level constant.
The next commit, introduce support for different CycloneDX spec version.

Thanks!
Quentin
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#13 lore raw

Re: [Buildroot] [PATCH 5/9] utils/generate-cyclonedx: move license download in a function

In reply to Thomas Perale via buildroot

In reply of:

Quoted 9 lines

Move the code that retrieve the SPDX licenses into a function instead of doing it top-level.

This allows to pass the CycloneDX version as a function argument instead of defining it as a top-level constant.
The next commit, introduce support for different CycloneDX spec version.

Applied to 2025.02.x, 2026.08.x. Thanks

Quoted 89 lines
---
 utils/generate-cyclonedx | 60 ++++++++++++++++++++++++++--------------
 1 file changed, 39 insertions(+), 21 deletions(-)
utils/generate-cyclonedx +38 -21
index 9e3bc9d4b8..9738db71d6 100755
@@ -23,12 +23,10 @@ import re
 
 
 CYCLONEDX_VERSION = "1.6"
-SPDX_SCHEMA_URL = f"https://raw.githubusercontent.com/CycloneDX/specification/{CYCLONEDX_VERSION}/schema/spdx.schema.json"
 
 brpath = Path(__file__).parent.parent
 
 cyclonedxpath = Path(os.getenv("BR2_DL_DIR", brpath / "dl")) / "cyclonedx"
-SPDX_SCHEMA_PATH = cyclonedxpath / f"spdx-{CYCLONEDX_VERSION}.schema.json"
 
 BR2_VERSION_FULL = (
     subprocess.check_output(
@@ -45,28 +43,47 @@ VULN_WITH_PEDIGREE = set()
 
 SPDX_LICENSES = []
 
-if not SPDX_SCHEMA_PATH.exists():
-    if not importlib.util.find_spec("_ssl"):
-        print(f"ssl module required for downloading {SPDX_SCHEMA_URL}. Try enabling BR2_PACKAGE_HOST_PYTHON3_SSL.",
-              file=sys.stderr)
-        exit(1)
 
-    # Download the CycloneDX SPDX schema JSON, and cache it locally
-    cyclonedxpath.mkdir(parents=True, exist_ok=True)
+def br2_retrieve_spdx_licenses(version: str):
+    """Populate the list of supported SPDX licenses for a given CycloneDX
+    version. If the list is not present locally it will be downloaded
+    externally.
+
+    Args:
+        version (str): CycloneDX version
+
+    Returns:
+        The SPDX license list supported for the argument version.
+    """
+    SPDX_SCHEMA_URL = f"https://raw.githubusercontent.com/CycloneDX/specification/{version}/schema/spdx.schema.json"
+
+    ret = []
+    path = cyclonedxpath / f"spdx-{version}.schema.json"
+
+    if not path.exists():
+        # Download the CycloneDX SPDX schema JSON, and cache it locally
+        if not importlib.util.find_spec("_ssl"):
+            print(f"ssl module required for downloading {SPDX_SCHEMA_URL}. Try enabling BR2_PACKAGE_HOST_PYTHON3_SSL.",
+                  file=sys.stderr)
+            exit(1)
+
+        cyclonedxpath.mkdir(parents=True, exist_ok=True)
+        try:
+            urllib.request.urlretrieve(SPDX_SCHEMA_URL, path)
+        except urllib.error.URLError as e:
+            if "CERTIFICATE_VERIFY_FAILED" in str(e.reason):
+                raise Exception("Couldn't verify certificate. Try enabling BR2_PACKAGE_HOST_CA_CERTIFICATES.")
+            raise e
+
     try:
-        urllib.request.urlretrieve(SPDX_SCHEMA_URL, SPDX_SCHEMA_PATH)
-    except urllib.error.URLError as e:
-        if "CERTIFICATE_VERIFY_FAILED" in str(e.reason):
-            raise Exception("Couldn't verify certificate. Try enabling BR2_PACKAGE_HOST_CA_CERTIFICATES.")
-        raise e
+        with path.open() as f:
+            ret = json.load(f).get("enum", [])
+    except json.JSONDecodeError:
+        # In case of error the license will just not be matched to the SPDX names
+        # but the SBOM generation still work.
+        print(f"Failed to load the SPDX licenses file: {path}", file=sys.stderr)
 
-try:
-    with SPDX_SCHEMA_PATH.open() as f:
-        SPDX_LICENSES = json.load(f).get("enum", [])
-except json.JSONDecodeError:
-    # In case of error the license will just not be matched to the SPDX names
-    # but the SBOM generation still work.
-    print(f"Failed to load the SPDX licenses file: {SPDX_SCHEMA_PATH}", file=sys.stderr)
+    return ret
 
 
 def split_top_level_comma(subj):

utils/generate-cyclonedx def main(): · line 551

Quoted 7 lines
utils/generate-cyclonedx +1 -0
@@ -528,6 +545,7 @@ def main():
         parser.print_help()
         sys.exit(1)
 
+    SPDX_LICENSES.extend(br2_retrieve_spdx_licenses(CYCLONEDX_VERSION))
     show_info_dict = json.load(args.in_file)
 
     # Remove rootfs and virtual packages if not explicitly included

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#14 lore raw

PATCH 6/9 utils/generate-cyclonedx: support custom version

In reply to Thomas Perale via buildroot

Support using minor revision for CycloneDX 1.6 by passing the version from the command line. Currently supported:

- 1.6
- 1.6.1 [1]
- 1.6.2 (default) [2]

This is used to fetch the latest SPDX license list available upstream.

[1] https://github.com/CycloneDX/specification/releases/tag/1.6.1
[2] https://github.com/CycloneDX/specification/releases/tag/1.6.2

---
 utils/generate-cyclonedx | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
utils/generate-cyclonedx +8 -4
index 9738db71d6..8d055c3bbd 100755
@@ -22,7 +22,7 @@ import sys
 import re
 
 
-CYCLONEDX_VERSION = "1.6"
+DEFAULT_CYCLONEDX_VERSION = "1.6.2"
 
 brpath = Path(__file__).parent.parent
 
@@ -538,6 +538,9 @@ def main():
                         help="Specify the project name to use in the SBOM metadata (default:'buildroot')")
     parser.add_argument("--project-version", type=str, default=f"{BR2_VERSION_FULL}",
                         help="Specify the project version to use in the SBOM metadata (default: builroot version)")
+    parser.add_argument("--cdx-version", type=str, default=DEFAULT_CYCLONEDX_VERSION,
+                        choices=["1.6", "1.6.1", "1.6.2"],
+                        help=f"Set CycloneDX version (default: {DEFAULT_CYCLONEDX_VERSION})")
 
     args = parser.parse_args()
 
@@ -545,7 +548,7 @@ def main():
         parser.print_help()
         sys.exit(1)
 
-    SPDX_LICENSES.extend(br2_retrieve_spdx_licenses(CYCLONEDX_VERSION))
+    SPDX_LICENSES.extend(br2_retrieve_spdx_licenses(args.cdx_version))
     show_info_dict = json.load(args.in_file)
 
     # Remove rootfs and virtual packages if not explicitly included
@@ -553,10 +556,11 @@ def main():
     filtered_show_info_dict = {k: v for k, v in show_info_dict.items()
                                if ("rootfs" not in v["type"]) and (args.virtual or v["virtual"] is False)}
 
+    cdx_spec_version = ".".join(args.cdx_version.split(".")[:2])
     cyclonedx_dict = {
         "bomFormat": "CycloneDX",
-        "$schema": f"http://cyclonedx.org/schema/bom-{CYCLONEDX_VERSION}.schema.json",
-        "specVersion": f"{CYCLONEDX_VERSION}",
+        "$schema": f"http://cyclonedx.org/schema/bom-{cdx_spec_version}.schema.json",
+        "specVersion": cdx_spec_version,
         "metadata": {
             "component": {
                 "bom-ref": args.project_name,
Signature · 6 lines
2.54.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#15 lore raw

Re: [Buildroot] [PATCH 6/9] utils/generate-cyclonedx: support custom version

Hi Thomas,

Quoted 9 lines · Thomas Perale

Support using minor revision for CycloneDX 1.6 by passing the version from the command line. Currently supported:

- 1.6
- 1.6.1 [1]
- 1.6.2 (default) [2]

This is used to fetch the latest SPDX license list available upstream.

Yeah it's kinda confusing to use the CycloneDX version to fetch something that's very little related to it (SPDX license list). I'm not even sure if it is actually required by the CycloneDX spec to use a specific version of the SPDX license list? Like I wouldn't understand why it needs to be a specific version, it's a list of SPDX-supported license, there's nothing that should break backward/forward-compatibility no?

Quoted 22 lines

[1] https://github.com/CycloneDX/specification/releases/tag/1.6.1
[2] https://github.com/CycloneDX/specification/releases/tag/1.6.2

---
  utils/generate-cyclonedx | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
utils/generate-cyclonedx +1 -1
index 9738db71d6..8d055c3bbd 100755
@@ -22,7 +22,7 @@ import sys
  import re
 
 
-CYCLONEDX_VERSION = "1.6"
+DEFAULT_CYCLONEDX_VERSION = "1.6.2"
 
  brpath = Path(__file__).parent.parent
 

utils/generate-cyclonedx def main(): · line 543

Quoted 6 lines
utils/generate-cyclonedx +3 -0
@@ -538,6 +538,9 @@ def main():
                          help="Specify the project name to use in the SBOM metadata (default:'buildroot')")
      parser.add_argument("--project-version", type=str, default=f"{BR2_VERSION_FULL}",
                          help="Specify the project version to use in the SBOM metadata (default: builroot version)")
+    parser.add_argument("--cdx-version", type=str, default=DEFAULT_CYCLONEDX_VERSION,
+                        choices=["1.6", "1.6.1", "1.6.2"],
+                        help=f"Set CycloneDX version (default: {DEFAULT_CYCLONEDX_VERSION})")

Simply use %(default)s in lieu of {DEFAULT_CYCLONEDX_VERSION} (and remove the f that makes the string an f-string). c.f. https://docs.python.org/3/library/argparse.html#help

I could nitpick here and say you should first add support for picking a version, and then another commit to modify the default version.

Quoted 13 lines
utils/generate-cyclonedx +1 -1
      args = parser.parse_args()
 
@@ -545,7 +548,7 @@ def main():
          parser.print_help()
          sys.exit(1)
 
-    SPDX_LICENSES.extend(br2_retrieve_spdx_licenses(CYCLONEDX_VERSION))
+    SPDX_LICENSES.extend(br2_retrieve_spdx_licenses(args.cdx_version))
      show_info_dict = json.load(args.in_file)
 
      # Remove rootfs and virtual packages if not explicitly included

utils/generate-cyclonedx def main(): · line 559

Quoted 4 lines
utils/generate-cyclonedx +1 -0
@@ -553,10 +556,11 @@ def main():
      filtered_show_info_dict = {k: v for k, v in show_info_dict.items()
                                 if ("rootfs" not in v["type"]) and (args.virtual or v["virtual"] is False)}
 
+    cdx_spec_version = ".".join(args.cdx_version.split(".")[:2])

Please add a comment here to explain why we're doing this.

Looks good to me otherwise.

Cheers,
Quentin
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#16 lore raw

Re: [Buildroot] [PATCH 6/9] utils/generate-cyclonedx: support custom version

Hi Quentin,

Coming back to you a bit late but I want to thank you for the thorough review.

We forgot to address those two comments before applying but I've sent a follow-up patch [1] to address your comments.

[1] https://lore.kernel.org/all/[email protected]/

Best regards,
PERALE Thomas

In reply of:

Quoted 54 lines

Hi Thomas,

Quoted 7 lines · Thomas Perale

Support using minor revision for CycloneDX 1.6 by passing the version from the command line. Currently supported:

Quoted 1 line

- 1.6

- 1.6.1 [1]
- 1.6.2 (default) [2]

Quoted 1 line

This is used to fetch the latest SPDX license list available upstream.

Yeah it's kinda confusing to use the CycloneDX version to fetch something that's very little related to it (SPDX license list). I'm not even sure if it is actually required by the CycloneDX spec to use a specific version of the SPDX license list? Like I wouldn't understand why it needs to be a specific version, it's a list of SPDX-supported license, there's nothing that should break backward/forward-compatibility no?

Quoted 12 lines

[1] https://github.com/CycloneDX/specification/releases/tag/1.6.1
[2] https://github.com/CycloneDX/specification/releases/tag/1.6.2

Quoted 1 line
---
  utils/generate-cyclonedx | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)

utils/generate-cyclonedx

Quoted 1 line
utils/generate-cyclonedx +0 -0

index 9738db71d6..8d055c3bbd 100755

utils/generate-cyclonedx +0 -0
@@ -22,7 +22,7 @@ import sys
  import re

utils/generate-cyclonedx import sys · line 543

Quoted 10 lines
utils/generate-cyclonedx +4 -0
  >   > -CYCLONEDX_VERSION = "1.6"
+DEFAULT_CYCLONEDX_VERSION = "1.6.2"
  >   brpath = Path(__file__).parent.parent
  > @@ -538,6 +538,9 @@ def main():
                          help="Specify the project name to use in the SBOM metadata (default:'buildroot')")
      parser.add_argument("--project-version", type=str, default=f"{BR2_VERSION_FULL}",
                          help="Specify the project version to use in the SBOM metadata (default: builroot version)")
+    parser.add_argument("--cdx-version", type=str, default=DEFAULT_CYCLONEDX_VERSION,
+                        choices=["1.6", "1.6.1", "1.6.2"],
+                        help=f"Set CycloneDX version (default: {DEFAULT_CYCLONEDX_VERSION})")

Simply use %(default)s in lieu of {DEFAULT_CYCLONEDX_VERSION} (and remove the f that makes the string an f-string). c.f. https://docs.python.org/3/library/argparse.html#help

I could nitpick here and say you should first add support for picking a version, and then another commit to modify the default version.

utils/generate-cyclonedx def main(): · line 558

Quoted 12 lines

utils/generate-cyclonedx def main():

Quoted 2 lines

args = parser.parse_args()

utils/generate-cyclonedx +0 -0
@@ -545,7 +548,7 @@ def main():
          parser.print_help()
          sys.exit(1)
Quoted 1 line
utils/generate-cyclonedx +0 -1
-    SPDX_LICENSES.extend(br2_retrieve_spdx_licenses(CYCLONEDX_VERSION))
utils/generate-cyclonedx +1 -0
+    SPDX_LICENSES.extend(br2_retrieve_spdx_licenses(args.cdx_version))
      show_info_dict = json.load(args.in_file)
  >       # Remove rootfs and virtual packages if not explicitly included
@@ -553,10 +556,11 @@ def main():
      filtered_show_info_dict = {k: v for k, v in show_info_dict.items()
                                 if ("rootfs" not in v["type"]) and (args.virtual or v["virtual"] is False)}
  > +    cdx_spec_version = ".".join(args.cdx_version.split(".")[:2])

Please add a comment here to explain why we're doing this.

Quoted 8 lines

Looks good to me otherwise.

Cheers,
Quentin
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#17 lore raw

Re: [Buildroot] [PATCH 6/9] utils/generate-cyclonedx: support custom version

In reply to Thomas Perale via buildroot
Quoted 22 lines · Thomas Perale via buildroot

Support using minor revision for CycloneDX 1.6 by passing the version from the command line. Currently supported:

- 1.6
- 1.6.1 [1]
- 1.6.2 (default) [2]

This is used to fetch the latest SPDX license list available upstream.

[1] https://github.com/CycloneDX/specification/releases/tag/1.6.1
[2] https://github.com/CycloneDX/specification/releases/tag/1.6.2

---
  utils/generate-cyclonedx | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
utils/generate-cyclonedx +0 -0
index 9738db71d6..8d055c3bbd 100755

utils/generate-cyclonedx import sys · line 25

Quoted 5 lines
utils/generate-cyclonedx +1 -1
@@ -22,7 +22,7 @@ import sys
  import re
 
 
-CYCLONEDX_VERSION = "1.6"
+DEFAULT_CYCLONEDX_VERSION = "1.6.2"

The test was still using version 1.6. This doesn't break the test because it's
only to generate a dummy file that avoids having to download it - so it just means that the test actually downloads the file, which fails when it is run without network. Not critical but I fixed it anyway.

Regards,
Arnout

Quoted 26 lines
utils/generate-cyclonedx +4 -1
  brpath = Path(__file__).parent.parent
 
@@ -538,6 +538,9 @@ def main():
                          help="Specify the project name to use in the SBOM metadata (default:'buildroot')")
      parser.add_argument("--project-version", type=str, default=f"{BR2_VERSION_FULL}",
                          help="Specify the project version to use in the SBOM metadata (default: builroot version)")
+    parser.add_argument("--cdx-version", type=str, default=DEFAULT_CYCLONEDX_VERSION,
+                        choices=["1.6", "1.6.1", "1.6.2"],
+                        help=f"Set CycloneDX version (default: {DEFAULT_CYCLONEDX_VERSION})")
 
      args = parser.parse_args()
 
@@ -545,7 +548,7 @@ def main():
          parser.print_help()
          sys.exit(1)
 
-    SPDX_LICENSES.extend(br2_retrieve_spdx_licenses(CYCLONEDX_VERSION))
+    SPDX_LICENSES.extend(br2_retrieve_spdx_licenses(args.cdx_version))
      show_info_dict = json.load(args.in_file)
 
      # Remove rootfs and virtual packages if not explicitly included
@@ -553,10 +556,11 @@ def main():
      filtered_show_info_dict = {k: v for k, v in show_info_dict.items()
                                 if ("rootfs" not in v["type"]) and (args.virtual or v["virtual"] is False)}
 

utils/generate-cyclonedx def main(): · line 566

Quoted 10 lines
utils/generate-cyclonedx +3 -2
+    cdx_spec_version = ".".join(args.cdx_version.split(".")[:2])
      cyclonedx_dict = {
          "bomFormat": "CycloneDX",
-        "$schema": f"http://cyclonedx.org/schema/bom-{CYCLONEDX_VERSION}.schema.json",
-        "specVersion": f"{CYCLONEDX_VERSION}",
+        "$schema": f"http://cyclonedx.org/schema/bom-{cdx_spec_version}.schema.json",
+        "specVersion": cdx_spec_version,
          "metadata": {
              "component": {
                  "bom-ref": args.project_name,

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#18 lore raw

Re: [Buildroot] [PATCH 6/9] utils/generate-cyclonedx: support custom version

In reply to Thomas Perale via buildroot

In reply of:

Quoted 7 lines

Support using minor revision for CycloneDX 1.6 by passing the version from the command line. Currently supported:

- 1.6
- 1.6.1 [1]
- 1.6.2 (default) [2]

Quoted 6 lines

This is used to fetch the latest SPDX license list available upstream.

[1] https://github.com/CycloneDX/specification/releases/tag/1.6.1
[2] https://github.com/CycloneDX/specification/releases/tag/1.6.2

Applied to 2025.02.x, 2026.08.x. Thanks

Quoted 40 lines
---
 utils/generate-cyclonedx | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
utils/generate-cyclonedx +5 -2
index 9738db71d6..8d055c3bbd 100755
@@ -22,7 +22,7 @@ import sys
 import re
 
 
-CYCLONEDX_VERSION = "1.6"
+DEFAULT_CYCLONEDX_VERSION = "1.6.2"
 
 brpath = Path(__file__).parent.parent
 
@@ -538,6 +538,9 @@ def main():
                         help="Specify the project name to use in the SBOM metadata (default:'buildroot')")
     parser.add_argument("--project-version", type=str, default=f"{BR2_VERSION_FULL}",
                         help="Specify the project version to use in the SBOM metadata (default: builroot version)")
+    parser.add_argument("--cdx-version", type=str, default=DEFAULT_CYCLONEDX_VERSION,
+                        choices=["1.6", "1.6.1", "1.6.2"],
+                        help=f"Set CycloneDX version (default: {DEFAULT_CYCLONEDX_VERSION})")
 
     args = parser.parse_args()
 
@@ -545,7 +548,7 @@ def main():
         parser.print_help()
         sys.exit(1)
 
-    SPDX_LICENSES.extend(br2_retrieve_spdx_licenses(CYCLONEDX_VERSION))
+    SPDX_LICENSES.extend(br2_retrieve_spdx_licenses(args.cdx_version))
     show_info_dict = json.load(args.in_file)
 
     # Remove rootfs and virtual packages if not explicitly included
@@ -553,10 +556,11 @@ def main():
     filtered_show_info_dict = {k: v for k, v in show_info_dict.items()
                                if ("rootfs" not in v["type"]) and (args.virtual or v["virtual"] is False)}
 

utils/generate-cyclonedx def main(): · line 566

Quoted 10 lines
utils/generate-cyclonedx +3 -2
+    cdx_spec_version = ".".join(args.cdx_version.split(".")[:2])
     cyclonedx_dict = {
         "bomFormat": "CycloneDX",
-        "$schema": f"http://cyclonedx.org/schema/bom-{CYCLONEDX_VERSION}.schema.json",
-        "specVersion": f"{CYCLONEDX_VERSION}",
+        "$schema": f"http://cyclonedx.org/schema/bom-{cdx_spec_version}.schema.json",
+        "specVersion": cdx_spec_version,
         "metadata": {
             "component": {
                 "bom-ref": args.project_name,

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#19 lore raw

PATCH 7/9 utils/generate-cyclonedx: support for v1.7, 1.7.1

In reply to Thomas Perale via buildroot

See changes:

- https://cyclonedx.org/news/cyclonedx-v1.7-released/
- https://github.com/CycloneDX/specification/releases/tag/1.7
- https://github.com/CycloneDX/specification/releases/tag/1.7.1

Since some tools like DependencyTrack don't support CycloneDX SBOM v1.7 this bump is optional and default remains v1.6.

---
 utils/generate-cyclonedx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
utils/generate-cyclonedx +1 -1
index 8d055c3bbd..672e7ed815 100755
@@ -539,7 +539,7 @@ def main():
     parser.add_argument("--project-version", type=str, default=f"{BR2_VERSION_FULL}",
                         help="Specify the project version to use in the SBOM metadata (default: builroot version)")
     parser.add_argument("--cdx-version", type=str, default=DEFAULT_CYCLONEDX_VERSION,
-                        choices=["1.6", "1.6.1", "1.6.2"],
+                        choices=["1.6", "1.6.1", "1.6.2", "1.7", "1.7.1"],
                         help=f"Set CycloneDX version (default: {DEFAULT_CYCLONEDX_VERSION})")
 
     args = parser.parse_args()
Signature · 6 lines
2.54.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
author Reviewed-by Quentin Schulz on v1 7/9
#20 lore raw

Re: [Buildroot] [PATCH 7/9] utils/generate-cyclonedx: support for v1.7, 1.7.1

Hi Thomas,

Quoted 6 lines · Thomas Perale

See changes:

- https://cyclonedx.org/news/cyclonedx-v1.7-released/
- https://github.com/CycloneDX/specification/releases/tag/1.7
- https://github.com/CycloneDX/specification/releases/tag/1.7.1

Seems like there are no breaking changes, so this very simple patch seems correct to me, thus:

Thanks!
Quentin
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#21 lore raw

Re: [Buildroot] [PATCH 7/9] utils/generate-cyclonedx: support for v1.7, 1.7.1

In reply to Thomas Perale via buildroot

In reply of:

Quoted 11 lines

See changes:

- https://cyclonedx.org/news/cyclonedx-v1.7-released/
- https://github.com/CycloneDX/specification/releases/tag/1.7
- https://github.com/CycloneDX/specification/releases/tag/1.7.1

Since some tools like DependencyTrack don't support CycloneDX SBOM v1.7 this bump is optional and default remains v1.6.

Applied to 2025.02.x, 2026.08.x. Thanks

Quoted 9 lines
---
 utils/generate-cyclonedx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
utils/generate-cyclonedx +0 -0
index 8d055c3bbd..672e7ed815 100755

utils/generate-cyclonedx def main(): · line 545

Quoted 8 lines
utils/generate-cyclonedx +1 -1
@@ -539,7 +539,7 @@ def main():
     parser.add_argument("--project-version", type=str, default=f"{BR2_VERSION_FULL}",
                         help="Specify the project version to use in the SBOM metadata (default: builroot version)")
     parser.add_argument("--cdx-version", type=str, default=DEFAULT_CYCLONEDX_VERSION,
-                        choices=["1.6", "1.6.1", "1.6.2"],
+                        choices=["1.6", "1.6.1", "1.6.2", "1.7", "1.7.1"],
                         help=f"Set CycloneDX version (default: {DEFAULT_CYCLONEDX_VERSION})")
 
     args = parser.parse_args()

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#22 lore raw

PATCH 8/9 utils/generate-cyclonedx: split vulnerabilities per state

In reply to Thomas Perale via buildroot

If a vulnerability is present in multiple components and only one of them has a patch that addresses that vulnerability, all components will currently have that vulnerability marked as resolved_with_pedigree.

Right now, this issue does not affect any packages, but in the future it might affect packages that provide multiple version options (e.g. gnupg and gnupg2).

There is a small chance this happens in a real-world use case, but it may occur in the context of maintenance when running
make show-info-all.

This commit changes how vulnerabilities fixed by a patch are stored. Instead of placing all vulnerabilities into a single set, it now keeps an index of the component for which the patch has been applied.

When generating the vulnerability list, the component reference is checked instead of only the vulnerability ID. If a vulnerability ID has multiple states for different references, multiple vulnerability entries are created with distinct analyses.

Consider the hypothetical case where gnupg ignores a vulnerability because it was introduced in a later version, while gnupg2 has patched that vulnerability. This would result in the following JSON:

```json
[
    {
        "id": "CVE-1234-1234",
        "analysis": {
            "state": "in_triage",
            "detail": "The CVE 'CVE-1234-1234' has been marked as ignored by Buildroot"
        },
        "affects": [
            {"ref": "gnupg"}
        ]
    },
    {
        "id": "CVE-1234-1234",
        "analysis": {
            "state": "resolved_with_pedigree",
            "detail": "The CVE 'CVE-1234-1234' has been marked as ignored by Buildroot"
        },
        "affects": [
            {"ref": "gnupg2"}
        ]
    }
]
```
---
 utils/generate-cyclonedx | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
utils/generate-cyclonedx +13 -8
index 672e7ed815..e12a9a4629 100755
@@ -14,6 +14,7 @@ import json
 import os
 from pathlib import Path
 from typing import Iterator
+from collections import defaultdict
 import urllib.parse
 import urllib.request
 import urllib.error
@@ -39,7 +40,7 @@ BR2_VERSION_FULL = (
 # Set of vulnerabilities that were addressed by a patch present in buildroot
 # tree. This set is used to set the analysis of the ignored CVEs to
 # 'resolved_with_pedigree'.
-VULN_WITH_PEDIGREE = set()
+VULN_WITH_PEDIGREE = defaultdict(set)
 
 SPDX_LICENSES = []
 
@@ -218,11 +219,12 @@ def read_patch_file(patch_path: Path) -> str:
         return f.read()
 
 
-def cyclonedx_patches(patch_list: list[str]):
+def cyclonedx_patches(comp_ref: str, patch_list: list[str]):
     """Translate a list of patches from the show-info JSON to a list of
     patches in CycloneDX format.
 
     Args:
+        comp_ref (str): Reference of the component the patches are part of.
         patch_list (list): Array of patch relative paths for a given component.
 
     Returns:
@@ -245,7 +247,7 @@ def cyclonedx_patches(patch_list: list[str]):
             issue = {}
             cves = extract_cves_from_header(header)
             if cves:
-                VULN_WITH_PEDIGREE.update(cves)
+                VULN_WITH_PEDIGREE[comp_ref].update(cves)
                 issue = {
                     "resolves": [
                         {
@@ -402,7 +404,7 @@ def cyclonedx_component(name, comp):
             "cpe": comp["cpe-id"],
         } if "cpe-id" in comp else {}),
         **cyclonedx_external_refs(comp),
-        **(cyclonedx_patches(comp["patches"]) if comp.get("patches") else {}),
+        **(cyclonedx_patches(name, comp["patches"]) if comp.get("patches") else {}),
         "properties": [{
             "name": "BR_TYPE",
             "value": comp["type"],
@@ -437,11 +439,14 @@ def cyclonedx_vulnerabilities(show_info_dict):
     Returns:
         list: Solved vulnerabilities list in CycloneDX format.
     """
-    cves = {}
+    cves = defaultdict(list)
 
     for name, comp in show_info_dict.items():
         for cve in comp.get('ignore_cves', []):
-            cves.setdefault(cve, []).append(name)
+            state = "in_triage"
+            if cve in VULN_WITH_PEDIGREE.get(name, {}):
+                state = "resolved_with_pedigree"
+            cves[(cve, state)].append(name)
 
     return [{
         "id": cve,
@@ -450,13 +455,13 @@ def cyclonedx_vulnerabilities(show_info_dict):
             "url": "https://nvd.nist.gov/vuln/detail/" + cve
         },
         "analysis": {
-            "state": "resolved_with_pedigree" if cve in VULN_WITH_PEDIGREE else "in_triage",
+            "state": state,
             "detail": f"The CVE '{cve}' has been marked as ignored by Buildroot"
         },
         "affects": [
             {"ref": bomref} for bomref in components
         ]
-    } for cve, components in cves.items()]
+    } for (cve, state), components in cves.items()]
 
 
 def br2_virtual_is_provided_by(ref, show_info_dict) -> list:
Signature · 6 lines
2.54.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#23 lore raw

Re: [Buildroot] [PATCH 8/9] utils/generate-cyclonedx: split vulnerabilities per state

Hi Thomas,

Quoted 68 lines · Thomas Perale

If a vulnerability is present in multiple components and only one of them has a patch that addresses that vulnerability, all components will currently have that vulnerability marked as resolved_with_pedigree.

Right now, this issue does not affect any packages, but in the future it might affect packages that provide multiple version options (e.g. gnupg and gnupg2).

There is a small chance this happens in a real-world use case, but it may occur in the context of maintenance when running
make show-info-all.

This commit changes how vulnerabilities fixed by a patch are stored. Instead of placing all vulnerabilities into a single set, it now keeps an index of the component for which the patch has been applied.

When generating the vulnerability list, the component reference is checked instead of only the vulnerability ID. If a vulnerability ID has multiple states for different references, multiple vulnerability entries are created with distinct analyses.

Consider the hypothetical case where gnupg ignores a vulnerability because it was introduced in a later version, while gnupg2 has patched that vulnerability. This would result in the following JSON:

```json
[
     {
         "id": "CVE-1234-1234",
         "analysis": {
             "state": "in_triage",
             "detail": "The CVE 'CVE-1234-1234' has been marked as ignored by Buildroot"
         },
         "affects": [
             {"ref": "gnupg"}
         ]
     },
     {
         "id": "CVE-1234-1234",
         "analysis": {
             "state": "resolved_with_pedigree",
             "detail": "The CVE 'CVE-1234-1234' has been marked as ignored by Buildroot"
         },
         "affects": [
             {"ref": "gnupg2"}
         ]
     }
]
```
---
  utils/generate-cyclonedx | 21 +++++++++++++--------
  1 file changed, 13 insertions(+), 8 deletions(-)
utils/generate-cyclonedx +1 -0
index 672e7ed815..e12a9a4629 100755
@@ -14,6 +14,7 @@ import json
  import os
  from pathlib import Path
  from typing import Iterator
+from collections import defaultdict
  import urllib.parse
  import urllib.request
  import urllib.error

utils/generate-cyclonedx BR2_VERSION_FULL = ( · line 42

Quoted 3 lines
utils/generate-cyclonedx +0 -0
@@ -39,7 +40,7 @@ BR2_VERSION_FULL = (
  # Set of vulnerabilities that were addressed by a patch present in buildroot
  # tree. This set is used to set the analysis of the ignored CVEs to
  # 'resolved_with_pedigree'.

It's not a set anymore, it's a dict with keyvalues being sets now, so please reflect this in the comment.

Quoted 6 lines
utils/generate-cyclonedx +1 -1
-VULN_WITH_PEDIGREE = set()
+VULN_WITH_PEDIGREE = defaultdict(set)
 
  SPDX_LICENSES = []
 

utils/generate-cyclonedx def read_patch_file(patch_path: Path) -> str: · line 227

Quoted 10 lines
utils/generate-cyclonedx +2 -1
@@ -218,11 +219,12 @@ def read_patch_file(patch_path: Path) -> str:
          return f.read()
 
 
-def cyclonedx_patches(patch_list: list[str]):
+def cyclonedx_patches(comp_ref: str, patch_list: list[str]):
      """Translate a list of patches from the show-info JSON to a list of
      patches in CycloneDX format.
 
      Args:
+        comp_ref (str): Reference of the component the patches are part of.

It's the bom-ref of the component related to the patches no?

Looks good to me otherwise!

Cheers,
Quentin
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#24 lore raw

Re: [Buildroot] [PATCH 8/9] utils/generate-cyclonedx: split vulnerabilities per state

In reply to Thomas Perale via buildroot
Quoted 60 lines · Thomas Perale via buildroot

If a vulnerability is present in multiple components and only one of them has a patch that addresses that vulnerability, all components will currently have that vulnerability marked as resolved_with_pedigree.

Right now, this issue does not affect any packages, but in the future it might affect packages that provide multiple version options (e.g. gnupg and gnupg2).

There is a small chance this happens in a real-world use case, but it may occur in the context of maintenance when running
make show-info-all.

This commit changes how vulnerabilities fixed by a patch are stored. Instead of placing all vulnerabilities into a single set, it now keeps an index of the component for which the patch has been applied.

When generating the vulnerability list, the component reference is checked instead of only the vulnerability ID. If a vulnerability ID has multiple states for different references, multiple vulnerability entries are created with distinct analyses.

Consider the hypothetical case where gnupg ignores a vulnerability because it was introduced in a later version, while gnupg2 has patched that vulnerability. This would result in the following JSON:

```json
[
     {
         "id": "CVE-1234-1234",
         "analysis": {
             "state": "in_triage",
             "detail": "The CVE 'CVE-1234-1234' has been marked as ignored by Buildroot"
         },
         "affects": [
             {"ref": "gnupg"}
         ]
     },
     {
         "id": "CVE-1234-1234",
         "analysis": {
             "state": "resolved_with_pedigree",
             "detail": "The CVE 'CVE-1234-1234' has been marked as ignored by Buildroot"
         },
         "affects": [
             {"ref": "gnupg2"}
         ]
     }
]
```
---
  utils/generate-cyclonedx | 21 +++++++++++++--------
  1 file changed, 13 insertions(+), 8 deletions(-)
utils/generate-cyclonedx +0 -0
index 672e7ed815..e12a9a4629 100755

utils/generate-cyclonedx import json · line 17

Quoted 4 lines
utils/generate-cyclonedx +1 -0
@@ -14,6 +14,7 @@ import json
  import os
  from pathlib import Path
  from typing import Iterator
+from collections import defaultdict

Alphabetic ordering again.

utils/generate-cyclonedx BR2_VERSION_FULL = ( · line 42

Quoted 7 lines
utils/generate-cyclonedx +0 -0
  import urllib.parse
  import urllib.request
  import urllib.error
@@ -39,7 +40,7 @@ BR2_VERSION_FULL = (
  # Set of vulnerabilities that were addressed by a patch present in buildroot
  # tree. This set is used to set the analysis of the ignored CVEs to
  # 'resolved_with_pedigree'.

The comment didn't correspond to the code anymore (it's not a set).

Quoted 39 lines
utils/generate-cyclonedx +5 -4
-VULN_WITH_PEDIGREE = set()
+VULN_WITH_PEDIGREE = defaultdict(set)
 
  SPDX_LICENSES = []
 
@@ -218,11 +219,12 @@ def read_patch_file(patch_path: Path) -> str:
          return f.read()
 
 
-def cyclonedx_patches(patch_list: list[str]):
+def cyclonedx_patches(comp_ref: str, patch_list: list[str]):
      """Translate a list of patches from the show-info JSON to a list of
      patches in CycloneDX format.
 
      Args:
+        comp_ref (str): Reference of the component the patches are part of.
          patch_list (list): Array of patch relative paths for a given component.
 
      Returns:
@@ -245,7 +247,7 @@ def cyclonedx_patches(patch_list: list[str]):
              issue = {}
              cves = extract_cves_from_header(header)
              if cves:
-                VULN_WITH_PEDIGREE.update(cves)
+                VULN_WITH_PEDIGREE[comp_ref].update(cves)
                  issue = {
                      "resolves": [
                          {
@@ -402,7 +404,7 @@ def cyclonedx_component(name, comp):
              "cpe": comp["cpe-id"],
          } if "cpe-id" in comp else {}),
          **cyclonedx_external_refs(comp),
-        **(cyclonedx_patches(comp["patches"]) if comp.get("patches") else {}),
+        **(cyclonedx_patches(name, comp["patches"]) if comp.get("patches") else {}),
          "properties": [{
              "name": "BR_TYPE",
              "value": comp["type"],
@@ -437,11 +439,14 @@ def cyclonedx_vulnerabilities(show_info_dict):
      Returns:

utils/generate-cyclonedx def cyclonedx_vulnerabilities(show_info_dict): · line 447

Quoted 10 lines
utils/generate-cyclonedx +3 -2
          list: Solved vulnerabilities list in CycloneDX format.
      """
-    cves = {}
+    cves = defaultdict(list)
 
      for name, comp in show_info_dict.items():
          for cve in comp.get('ignore_cves', []):
-            cves.setdefault(cve, []).append(name)
+            state = "in_triage"
+            if cve in VULN_WITH_PEDIGREE.get(name, {}):

Since VULN_WITH_PEDIGREE is a defaultdict of sets, it makes more sense to use
an empty set instead of an empty dict as default of the get(). Doesn't make any actual difference of course but if we'd ever do type checks this would trigger.

Regards,
Arnout

Quoted 11 lines
utils/generate-cyclonedx +3 -1
+                state = "resolved_with_pedigree"
+            cves[(cve, state)].append(name)
 
      return [{
          "id": cve,
@@ -450,13 +455,13 @@ def cyclonedx_vulnerabilities(show_info_dict):
              "url": "https://nvd.nist.gov/vuln/detail/" + cve
          },
          "analysis": {
-            "state": "resolved_with_pedigree" if cve in VULN_WITH_PEDIGREE else "in_triage",
+            "state": state,

utils/generate-cyclonedx def cyclonedx_vulnerabilities(show_info_dict): · line 467

Quoted 10 lines
utils/generate-cyclonedx +1 -1
              "detail": f"The CVE '{cve}' has been marked as ignored by Buildroot"
          },
          "affects": [
              {"ref": bomref} for bomref in components
          ]
-    } for cve, components in cves.items()]
+    } for (cve, state), components in cves.items()]
 
 
  def br2_virtual_is_provided_by(ref, show_info_dict) -> list:

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#25 lore raw

Re: [Buildroot] [PATCH 8/9] utils/generate-cyclonedx: split vulnerabilities per state

In reply to Thomas Perale via buildroot

In reply of:

Quoted 50 lines

If a vulnerability is present in multiple components and only one of them has a patch that addresses that vulnerability, all components will currently have that vulnerability marked as resolved_with_pedigree.

Right now, this issue does not affect any packages, but in the future it might affect packages that provide multiple version options (e.g. gnupg and gnupg2).

There is a small chance this happens in a real-world use case, but it may occur in the context of maintenance when running
make show-info-all.

This commit changes how vulnerabilities fixed by a patch are stored. Instead of placing all vulnerabilities into a single set, it now keeps an index of the component for which the patch has been applied.

When generating the vulnerability list, the component reference is checked instead of only the vulnerability ID. If a vulnerability ID has multiple states for different references, multiple vulnerability entries are created with distinct analyses.

Consider the hypothetical case where gnupg ignores a vulnerability because it was introduced in a later version, while gnupg2 has patched that vulnerability. This would result in the following JSON:

```json
[
    {
        "id": "CVE-1234-1234",
        "analysis": {
            "state": "in_triage",
            "detail": "The CVE 'CVE-1234-1234' has been marked as ignored by Buildroot"
        },
        "affects": [
            {"ref": "gnupg"}
        ]
    },
    {
        "id": "CVE-1234-1234",
        "analysis": {
            "state": "resolved_with_pedigree",
            "detail": "The CVE 'CVE-1234-1234' has been marked as ignored by Buildroot"
        },
        "affects": [
            {"ref": "gnupg2"}
        ]
    }
]
```
Quoted 1 line

Applied to 2025.02.x, 2026.08.x. Thanks

Quoted 80 lines
---
 utils/generate-cyclonedx | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
utils/generate-cyclonedx +12 -7
index 672e7ed815..e12a9a4629 100755
@@ -14,6 +14,7 @@ import json
 import os
 from pathlib import Path
 from typing import Iterator
+from collections import defaultdict
 import urllib.parse
 import urllib.request
 import urllib.error
@@ -39,7 +40,7 @@ BR2_VERSION_FULL = (
 # Set of vulnerabilities that were addressed by a patch present in buildroot
 # tree. This set is used to set the analysis of the ignored CVEs to
 # 'resolved_with_pedigree'.
-VULN_WITH_PEDIGREE = set()
+VULN_WITH_PEDIGREE = defaultdict(set)
 
 SPDX_LICENSES = []
 
@@ -218,11 +219,12 @@ def read_patch_file(patch_path: Path) -> str:
         return f.read()
 
 
-def cyclonedx_patches(patch_list: list[str]):
+def cyclonedx_patches(comp_ref: str, patch_list: list[str]):
     """Translate a list of patches from the show-info JSON to a list of
     patches in CycloneDX format.
 
     Args:
+        comp_ref (str): Reference of the component the patches are part of.
         patch_list (list): Array of patch relative paths for a given component.
 
     Returns:
@@ -245,7 +247,7 @@ def cyclonedx_patches(patch_list: list[str]):
             issue = {}
             cves = extract_cves_from_header(header)
             if cves:
-                VULN_WITH_PEDIGREE.update(cves)
+                VULN_WITH_PEDIGREE[comp_ref].update(cves)
                 issue = {
                     "resolves": [
                         {
@@ -402,7 +404,7 @@ def cyclonedx_component(name, comp):
             "cpe": comp["cpe-id"],
         } if "cpe-id" in comp else {}),
         **cyclonedx_external_refs(comp),
-        **(cyclonedx_patches(comp["patches"]) if comp.get("patches") else {}),
+        **(cyclonedx_patches(name, comp["patches"]) if comp.get("patches") else {}),
         "properties": [{
             "name": "BR_TYPE",
             "value": comp["type"],
@@ -437,11 +439,14 @@ def cyclonedx_vulnerabilities(show_info_dict):
     Returns:
         list: Solved vulnerabilities list in CycloneDX format.
     """
-    cves = {}
+    cves = defaultdict(list)
 
     for name, comp in show_info_dict.items():
         for cve in comp.get('ignore_cves', []):
-            cves.setdefault(cve, []).append(name)
+            state = "in_triage"
+            if cve in VULN_WITH_PEDIGREE.get(name, {}):
+                state = "resolved_with_pedigree"
+            cves[(cve, state)].append(name)
 
     return [{
         "id": cve,
@@ -450,13 +455,13 @@ def cyclonedx_vulnerabilities(show_info_dict):
             "url": "https://nvd.nist.gov/vuln/detail/" + cve
         },
         "analysis": {
-            "state": "resolved_with_pedigree" if cve in VULN_WITH_PEDIGREE else "in_triage",
+            "state": state,

utils/generate-cyclonedx def cyclonedx_vulnerabilities(show_info_dict): · line 467

Quoted 10 lines
utils/generate-cyclonedx +1 -1
             "detail": f"The CVE '{cve}' has been marked as ignored by Buildroot"
         },
         "affects": [
             {"ref": bomref} for bomref in components
         ]
-    } for cve, components in cves.items()]
+    } for (cve, state), components in cves.items()]
 
 
 def br2_virtual_is_provided_by(ref, show_info_dict) -> list:

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#26 lore raw

PATCH 9/9 testing/tests/utils/test_generate_cyclonedx.py: test vuln with different analysis

In reply to Thomas Perale via buildroot

Add test for CycloneDX vulnerability generation.

If multiple packages ignore the same vulnerability but provide different analyses, the generator must produce multiple vulnerability entries with the same vulnerability ID but different analysis information.

This situation can occur when generating a CycloneDX SBOM from the output of 'make show-info-all'. The resulting SBOM includes packages that exist in multiple versions within Buildroot (gnupg for instance).

In such a case, one package version may ignore a vulnerability because it is not affected, while another package version may address it through a patch.

Therefore, multiple vulnerability entries must be generated, each with its own analysis and reference information.

This add test case for such scenario.

---
 .../tests/utils/test_generate_cyclonedx.py    | 69 ++++++++++++++++++-
 1 file changed, 66 insertions(+), 3 deletions(-)
support/testing/tests/utils/test_generate_cyclonedx.py +66 -3
index b91add2349..2f1109b178 100644
@@ -6,6 +6,7 @@ import subprocess
 import tempfile
 import unittest
 from pathlib import Path
+from collections import defaultdict
 
 import infra
 
@@ -100,15 +101,23 @@ class TestGenerateCycloneDX(unittest.TestCase):
                 return component
         self.fail(f"component {name} missing")
 
+    def _map_vulnerabilities(self, result: dict) -> dict:
+        vuln_map = defaultdict(list)
+        for vuln in result["vulnerabilities"]:
+            vuln_map[vuln["id"]].append(vuln)
+        return vuln_map
+
     def test_default(self):
         result = self._run_script()
 
         self.assertEqual(len(result["components"]), 4)
         self.assertIn("vulnerabilities", result)
-        vulnerabilities = {v["id"]: v for v in result["vulnerabilities"]}
+        vulnerabilities = self._map_vulnerabilities(result)
         self.assertEqual(len(vulnerabilities), 2)
-        self.assertEqual(vulnerabilities["CVE-2025-0001"]["analysis"]["state"], "resolved_with_pedigree")
-        self.assertEqual(vulnerabilities["CVE-2025-0002"]["analysis"]["state"], "in_triage")
+        self.assertEqual(len(vulnerabilities["CVE-2025-0001"]), 1)
+        self.assertEqual(len(vulnerabilities["CVE-2025-0002"]), 1)
+        self.assertEqual(vulnerabilities["CVE-2025-0001"][0]["analysis"]["state"], "resolved_with_pedigree")
+        self.assertEqual(vulnerabilities["CVE-2025-0002"][0]["analysis"]["state"], "in_triage")
 
         foo = self._find_component(result, "package-foo")
         patch = foo["pedigree"]["patches"][0]
@@ -244,3 +253,57 @@ class TestGenerateCycloneDX(unittest.TestCase):
                 }
             ],
         )
+
+    def test_vulnerabilities_with_different_analysis(self):
+        """
+        If multiple packages ignore the same vulnerability but provide
+        different analyses, the generator must produce multiple
+        vulnerability entries with the same vulnerability ID but different
+        analysis information.
+
+        This situation can occur when generating a CycloneDX SBOM from the
+        output of 'make show-info-all'. The resulting SBOM includes packages
+        that exist in multiple versions within Buildroot (gnupg for instance).
+
+        In such a case, one package version may ignore a vulnerability because
+        it is not affected, while another package version may address it
+        through a patch.
+
+        Therefore, multiple vulnerability entries must be generated, each with
+        its own analysis and reference information.
+        """
+
+        info = {
+            "gnupg": {
+                "name": "gnupg",
+                "version": "1.4.23",
+                "type": "target",
+                "ignore_cves": ["CVE-2025-0001"],
+                "virtual": False,
+            },
+            "gnupg2": {
+                "name": "gnupg2",
+                "version": "2.5.20",
+                "type": "target",
+                "virtual": False,
+                "patches": [PATCH],
+                "ignore_cves": ["CVE-2025-0001"],
+            },
+        }
+
+        result = self._run_script(show_info=info)
+        self.assertEqual(len(result["vulnerabilities"]), 2)
+
+        vulnerabilities = self._map_vulnerabilities(result)
+
+        self.assertEqual(len(vulnerabilities["CVE-2025-0001"]), 2)
+
+        ignored = next(v for v in vulnerabilities["CVE-2025-0001"] if v["analysis"]["state"] == "in_triage")
+        self.assertTrue(ignored is not None)
+        self.assertEqual(len(ignored["affects"]), 1)
+        self.assertEqual(ignored["affects"][0]["ref"], "gnupg")
+
+        resolved = next(v for v in vulnerabilities["CVE-2025-0001"] if v["analysis"]["state"] == "resolved_with_pedigree")
+        self.assertTrue(resolved is not None)
+        self.assertEqual(len(resolved["affects"]), 1)
+        self.assertEqual(resolved["affects"][0]["ref"], "gnupg2")
Signature · 6 lines
2.54.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
author Reviewed-by Quentin Schulz on v1 9/9
#27 lore raw

Re: [Buildroot] [PATCH 9/9] testing/tests/utils/test_generate_cyclonedx.py: test vuln with different analysis

Hi Thomas,

Quoted 92 lines · Thomas Perale

Add test for CycloneDX vulnerability generation.

If multiple packages ignore the same vulnerability but provide different analyses, the generator must produce multiple vulnerability entries with the same vulnerability ID but different analysis information.

This situation can occur when generating a CycloneDX SBOM from the output of 'make show-info-all'. The resulting SBOM includes packages that exist in multiple versions within Buildroot (gnupg for instance).

In such a case, one package version may ignore a vulnerability because it is not affected, while another package version may address it through a patch.

Therefore, multiple vulnerability entries must be generated, each with its own analysis and reference information.

This add test case for such scenario.

---
  .../tests/utils/test_generate_cyclonedx.py    | 69 ++++++++++++++++++-
  1 file changed, 66 insertions(+), 3 deletions(-)
support/testing/tests/utils/test_generate_cyclonedx.py +37 -3
index b91add2349..2f1109b178 100644
@@ -6,6 +6,7 @@ import subprocess
  import tempfile
  import unittest
  from pathlib import Path
+from collections import defaultdict
 
  import infra
 
@@ -100,15 +101,23 @@ class TestGenerateCycloneDX(unittest.TestCase):
                  return component
          self.fail(f"component {name} missing")
 
+    def _map_vulnerabilities(self, result: dict) -> dict:
+        vuln_map = defaultdict(list)
+        for vuln in result["vulnerabilities"]:
+            vuln_map[vuln["id"]].append(vuln)
+        return vuln_map
+
      def test_default(self):
          result = self._run_script()
 
          self.assertEqual(len(result["components"]), 4)
          self.assertIn("vulnerabilities", result)
-        vulnerabilities = {v["id"]: v for v in result["vulnerabilities"]}
+        vulnerabilities = self._map_vulnerabilities(result)
          self.assertEqual(len(vulnerabilities), 2)
-        self.assertEqual(vulnerabilities["CVE-2025-0001"]["analysis"]["state"], "resolved_with_pedigree")
-        self.assertEqual(vulnerabilities["CVE-2025-0002"]["analysis"]["state"], "in_triage")
+        self.assertEqual(len(vulnerabilities["CVE-2025-0001"]), 1)
+        self.assertEqual(len(vulnerabilities["CVE-2025-0002"]), 1)
+        self.assertEqual(vulnerabilities["CVE-2025-0001"][0]["analysis"]["state"], "resolved_with_pedigree")
+        self.assertEqual(vulnerabilities["CVE-2025-0002"][0]["analysis"]["state"], "in_triage")
 
          foo = self._find_component(result, "package-foo")
          patch = foo["pedigree"]["patches"][0]
@@ -244,3 +253,57 @@ class TestGenerateCycloneDX(unittest.TestCase):
                  }
              ],
          )
+
+    def test_vulnerabilities_with_different_analysis(self):
+        """
+        If multiple packages ignore the same vulnerability but provide
+        different analyses, the generator must produce multiple
+        vulnerability entries with the same vulnerability ID but different
+        analysis information.
+
+        This situation can occur when generating a CycloneDX SBOM from the
+        output of 'make show-info-all'. The resulting SBOM includes packages
+        that exist in multiple versions within Buildroot (gnupg for instance).
+
+        In such a case, one package version may ignore a vulnerability because
+        it is not affected, while another package version may address it
+        through a patch.
+
+        Therefore, multiple vulnerability entries must be generated, each with
+        its own analysis and reference information.
+        """
+
+        info = {
+            "gnupg": {
+                "name": "gnupg",
+                "version": "1.4.23",
+                "type": "target",

support/testing/tests/utils/test_generate_cyclonedx.py class TestGenerateCycloneDX(unittest.TestCase): · line 290

Quoted 10 lines
support/testing/tests/utils/test_generate_cyclonedx.py +10 -0
+                "ignore_cves": ["CVE-2025-0001"],
+                "virtual": False,
+            },
+            "gnupg2": {
+                "name": "gnupg2",
+                "version": "2.5.20",
+                "type": "target",
+                "virtual": False,
+                "patches": [PATCH],
+                "ignore_cves": ["CVE-2025-0001"],

nitpick: reorder virtual+patches after ignore_cves in gnupg2 so it visually matches the order in gnupg.

Thanks!
Quentin
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#28 lore raw

Re: [Buildroot] [PATCH 9/9] testing/tests/utils/test_generate_cyclonedx.py: test vuln with different analysis

In reply to Thomas Perale via buildroot
Quoted 29 lines · Thomas Perale via buildroot

Add test for CycloneDX vulnerability generation.

If multiple packages ignore the same vulnerability but provide different analyses, the generator must produce multiple vulnerability entries with the same vulnerability ID but different analysis information.

This situation can occur when generating a CycloneDX SBOM from the output of 'make show-info-all'. The resulting SBOM includes packages that exist in multiple versions within Buildroot (gnupg for instance).

In such a case, one package version may ignore a vulnerability because it is not affected, while another package version may address it through a patch.

Therefore, multiple vulnerability entries must be generated, each with its own analysis and reference information.

This add test case for such scenario.

---
  .../tests/utils/test_generate_cyclonedx.py    | 69 ++++++++++++++++++-
  1 file changed, 66 insertions(+), 3 deletions(-)
support/testing/tests/utils/test_generate_cyclonedx.py +0 -0
index b91add2349..2f1109b178 100644

support/testing/tests/utils/test_generate_cyclonedx.py import subprocess · line 9

Quoted 4 lines
support/testing/tests/utils/test_generate_cyclonedx.py +1 -0
@@ -6,6 +6,7 @@ import subprocess
  import tempfile
  import unittest
  from pathlib import Path
+from collections import defaultdict

Darn, I missed this one.

support/testing/tests/utils/test_generate_cyclonedx.py import subprocess · line 12

Quoted 3 lines
support/testing/tests/utils/test_generate_cyclonedx.py +0 -0
  import infra
 

[snip]> +

support/testing/tests/utils/test_generate_cyclonedx.py class TestGenerateCycloneDX(unittest.TestCase): · line 301

Quoted 8 lines
support/testing/tests/utils/test_generate_cyclonedx.py +8 -0
+        result = self._run_script(show_info=info)
+        self.assertEqual(len(result["vulnerabilities"]), 2)
+
+        vulnerabilities = self._map_vulnerabilities(result)
+
+        self.assertEqual(len(vulnerabilities["CVE-2025-0001"]), 2)
+
+        ignored = next(v for v in vulnerabilities["CVE-2025-0001"] if v["analysis"]["state"] == "in_triage")

The next() doesn't return None if the set is empty, it raises StopIteration.
That does make the test fail, but it makes the assertion below useless. next() can take a second argument for the default, so I added that.

Quoted 1 line

+ self.assertTrue(ignored is not None)

This should be assertIsNotNone().

Regards,
Arnout

support/testing/tests/utils/test_generate_cyclonedx.py class TestGenerateCycloneDX(unittest.TestCase): · line 309

Quoted 7 lines
support/testing/tests/utils/test_generate_cyclonedx.py +7 -0
+        self.assertEqual(len(ignored["affects"]), 1)
+        self.assertEqual(ignored["affects"][0]["ref"], "gnupg")
+
+        resolved = next(v for v in vulnerabilities["CVE-2025-0001"] if v["analysis"]["state"] == "resolved_with_pedigree")
+        self.assertTrue(resolved is not None)
+        self.assertEqual(len(resolved["affects"]), 1)
+        self.assertEqual(resolved["affects"][0]["ref"], "gnupg2")

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#29 lore raw

Re: [Buildroot] [PATCH 9/9] testing/tests/utils/test_generate_cyclonedx.py: test vuln with different analysis

In reply to Thomas Perale via buildroot

In reply of:

Quoted 14 lines

Add test for CycloneDX vulnerability generation.

If multiple packages ignore the same vulnerability but provide different analyses, the generator must produce multiple vulnerability entries with the same vulnerability ID but different analysis information.

This situation can occur when generating a CycloneDX SBOM from the output of 'make show-info-all'. The resulting SBOM includes packages that exist in multiple versions within Buildroot (gnupg for instance).

In such a case, one package version may ignore a vulnerability because it is not affected, while another package version may address it through a patch.

Quoted 7 lines

Therefore, multiple vulnerability entries must be generated, each with its own analysis and reference information.

This add test case for such scenario.

Applied to 2025.02.x, 2026.08.x. Thanks

Quoted 91 lines
---
 .../tests/utils/test_generate_cyclonedx.py    | 69 ++++++++++++++++++-
 1 file changed, 66 insertions(+), 3 deletions(-)
support/testing/tests/utils/test_generate_cyclonedx.py +56 -3
index b91add2349..2f1109b178 100644
@@ -6,6 +6,7 @@ import subprocess
 import tempfile
 import unittest
 from pathlib import Path
+from collections import defaultdict
 
 import infra
 
@@ -100,15 +101,23 @@ class TestGenerateCycloneDX(unittest.TestCase):
                 return component
         self.fail(f"component {name} missing")
 
+    def _map_vulnerabilities(self, result: dict) -> dict:
+        vuln_map = defaultdict(list)
+        for vuln in result["vulnerabilities"]:
+            vuln_map[vuln["id"]].append(vuln)
+        return vuln_map
+
     def test_default(self):
         result = self._run_script()
 
         self.assertEqual(len(result["components"]), 4)
         self.assertIn("vulnerabilities", result)
-        vulnerabilities = {v["id"]: v for v in result["vulnerabilities"]}
+        vulnerabilities = self._map_vulnerabilities(result)
         self.assertEqual(len(vulnerabilities), 2)
-        self.assertEqual(vulnerabilities["CVE-2025-0001"]["analysis"]["state"], "resolved_with_pedigree")
-        self.assertEqual(vulnerabilities["CVE-2025-0002"]["analysis"]["state"], "in_triage")
+        self.assertEqual(len(vulnerabilities["CVE-2025-0001"]), 1)
+        self.assertEqual(len(vulnerabilities["CVE-2025-0002"]), 1)
+        self.assertEqual(vulnerabilities["CVE-2025-0001"][0]["analysis"]["state"], "resolved_with_pedigree")
+        self.assertEqual(vulnerabilities["CVE-2025-0002"][0]["analysis"]["state"], "in_triage")
 
         foo = self._find_component(result, "package-foo")
         patch = foo["pedigree"]["patches"][0]
@@ -244,3 +253,57 @@ class TestGenerateCycloneDX(unittest.TestCase):
                 }
             ],
         )
+
+    def test_vulnerabilities_with_different_analysis(self):
+        """
+        If multiple packages ignore the same vulnerability but provide
+        different analyses, the generator must produce multiple
+        vulnerability entries with the same vulnerability ID but different
+        analysis information.
+
+        This situation can occur when generating a CycloneDX SBOM from the
+        output of 'make show-info-all'. The resulting SBOM includes packages
+        that exist in multiple versions within Buildroot (gnupg for instance).
+
+        In such a case, one package version may ignore a vulnerability because
+        it is not affected, while another package version may address it
+        through a patch.
+
+        Therefore, multiple vulnerability entries must be generated, each with
+        its own analysis and reference information.
+        """
+
+        info = {
+            "gnupg": {
+                "name": "gnupg",
+                "version": "1.4.23",
+                "type": "target",
+                "ignore_cves": ["CVE-2025-0001"],
+                "virtual": False,
+            },
+            "gnupg2": {
+                "name": "gnupg2",
+                "version": "2.5.20",
+                "type": "target",
+                "virtual": False,
+                "patches": [PATCH],
+                "ignore_cves": ["CVE-2025-0001"],
+            },
+        }
+
+        result = self._run_script(show_info=info)
+        self.assertEqual(len(result["vulnerabilities"]), 2)
+
+        vulnerabilities = self._map_vulnerabilities(result)
+
+        self.assertEqual(len(vulnerabilities["CVE-2025-0001"]), 2)

support/testing/tests/utils/test_generate_cyclonedx.py class TestGenerateCycloneDX(unittest.TestCase): · line 309

Quoted 10 lines
support/testing/tests/utils/test_generate_cyclonedx.py +10 -0
+
+        ignored = next(v for v in vulnerabilities["CVE-2025-0001"] if v["analysis"]["state"] == "in_triage")
+        self.assertTrue(ignored is not None)
+        self.assertEqual(len(ignored["affects"]), 1)
+        self.assertEqual(ignored["affects"][0]["ref"], "gnupg")
+
+        resolved = next(v for v in vulnerabilities["CVE-2025-0001"] if v["analysis"]["state"] == "resolved_with_pedigree")
+        self.assertTrue(resolved is not None)
+        self.assertEqual(len(resolved["affects"]), 1)
+        self.assertEqual(resolved["affects"][0]["ref"], "gnupg2")

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#30 lore raw
In reply to Thomas Perale via buildroot
Quoted 8 lines · Thomas Perale via buildroot

The commit [1] fixed a formatting bug with the SCP style git sites declaration.

Add this style of link to the test case to keep a track of it.

[1] ebcfdb8b0a utils/generate-cyclonedx: fixup scp-style git sites

Applied series to master, thanks!

I did minor spelling corrections to commit messages along the way, and slightly
larger changes to some commits, which I'll reply to individually.

Regards,
Arnout

Quoted 30 lines
---
 support/testing/tests/utils/test_generate_cyclonedx.py | 6 ++++++
 1 file changed, 6 insertions(+)
support/testing/tests/utils/test_generate_cyclonedx.py +6 -0
index e6640fbd0d..b91add2349 100644
@@ -149,6 +149,7 @@ class TestGenerateCycloneDX(unittest.TestCase):
                 "uris": [
                     "git+git://git.example.org/foo",
                     "svn+https://svn.example.org/foo",
+                    "[email protected]:project/foo.git",
                     "https+https://sources.buildroot.net/foo",
                     "http|https+https://mirror.example.org/foo",
                 ],
@@ -172,6 +173,11 @@ class TestGenerateCycloneDX(unittest.TestCase):
                     "url": "https://svn.example.org/foo",
                     "comment": "svn repository",
                 },
+                {
+                    "type": "vcs",
+                    "url": "ssh://[email protected]/project/foo.git",
+                    "comment": "git repository",
+                },
                 {
                     "type": "source-distribution",
                     "url": "https://mirror.example.org/foo/foo-1.2.tar.gz",
Signature · 1 line
2.54.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#31 lore raw
In reply to Thomas Perale via buildroot

In reply of:

Quoted 9 lines

The commit [1] fixed a formatting bug with the SCP style git sites declaration.

Add this style of link to the test case to keep a track of it.

[1] ebcfdb8b0a utils/generate-cyclonedx: fixup scp-style git sites

Applied to 2025.02.x, 2026.08.x. Thanks

Quoted 18 lines
---
 support/testing/tests/utils/test_generate_cyclonedx.py | 6 ++++++
 1 file changed, 6 insertions(+)
support/testing/tests/utils/test_generate_cyclonedx.py +1 -0
index e6640fbd0d..b91add2349 100644
@@ -149,6 +149,7 @@ class TestGenerateCycloneDX(unittest.TestCase):
                 "uris": [
                     "git+git://git.example.org/foo",
                     "svn+https://svn.example.org/foo",
+                    "[email protected]:project/foo.git",
                     "https+https://sources.buildroot.net/foo",
                     "http|https+https://mirror.example.org/foo",
                 ],
@@ -172,6 +173,11 @@ class TestGenerateCycloneDX(unittest.TestCase):
                     "url": "https://svn.example.org/foo",

support/testing/tests/utils/test_generate_cyclonedx.py class TestGenerateCycloneDX(unittest.TestCase): · line 183

Quoted 10 lines
support/testing/tests/utils/test_generate_cyclonedx.py +5 -0
                     "comment": "svn repository",
                 },
+                {
+                    "type": "vcs",
+                    "url": "ssh://[email protected]/project/foo.git",
+                    "comment": "git repository",
+                },
                 {
                     "type": "source-distribution",
                     "url": "https://mirror.example.org/foo/foo-1.2.tar.gz",

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot