Skip to content

Commit

Permalink
fix(cyclonedx): add nil check to metadata.component (#2673)
Browse files Browse the repository at this point in the history
  • Loading branch information
masahiro331 authored Aug 8, 2022
1 parent 50db7da commit de365c8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"bomFormat": "CycloneDX",
"specVersion": "1.4",
"serialNumber": "urn:uuid:c986ba94-e37d-49c8-9e30-96daccd0415b",
"version": 1,
"metadata": {
"timestamp": "2022-05-28T10:20:03.79527Z",
"tools": [
{
"vendor": "aquasecurity",
"name": "trivy",
"version": "dev"
}
]
},
"dependencies": []
}
2 changes: 1 addition & 1 deletion pkg/sbom/cyclonedx/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func componentMap(metadata *cdx.Metadata, components *[]cdx.Component) map[strin
for _, component := range lo.FromPtr(components) {
cmap[component.BOMRef] = component
}
if metadata != nil {
if metadata != nil && metadata.Component != nil {
cmap[metadata.Component.BOMRef] = *metadata.Component
}
return cmap
Expand Down
5 changes: 5 additions & 0 deletions pkg/sbom/cyclonedx/unmarshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ func TestUnmarshaler_Unmarshal(t *testing.T) {
inputFile: "testdata/happy/empty-bom.json",
want: sbom.SBOM{},
},
{
name: "happy path empty metadata component",
inputFile: "testdata/happy/empty-metadata-component-bom.json",
want: sbom.SBOM{},
},
{
name: "sad path invalid purl",
inputFile: "testdata/sad/invalid-purl.json",
Expand Down

0 comments on commit de365c8

Please sign in to comment.