Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cyclonedx): add nil check to metadata.component #2673

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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