Skip to content
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
4 changes: 3 additions & 1 deletion schema/bom_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,9 @@ func (bom *BOM) HashmapVulnerability(cdxVulnerability CDXVulnerability, whereFil
vulnInfo.AnalysisJustification = VULN_ANALYSIS_STATE_EMPTY
}

vulnInfo.AnalysisResponse = *cdxVulnerability.Analysis.Response
if cdxVulnerability.Analysis.Response != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

vulnInfo.AnalysisResponse = *cdxVulnerability.Analysis.Response
}
if len(vulnInfo.AnalysisResponse) == 0 {
vulnInfo.AnalysisResponse = []string{VULN_ANALYSIS_STATE_EMPTY}
}
Expand Down
21 changes: 21 additions & 0 deletions schema/bom_hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,27 @@ func TestHashZeroCDXVulnerabilityStruct(t *testing.T) {
}
}

// Regression test for https://github.com/CycloneDX/sbom-utility/issues/148 :
// a vulnerability with an `analysis` object that omits the optional `response`
// array must not cause a nil pointer dereference panic.
func TestHashCDXVulnerabilityAnalysisWithoutResponse(t *testing.T) {
cdxVulnerability := CDXVulnerability{
Id: "CVE-2026-0000",
Analysis: &CDXAnalysis{
State: "exploitable",
},
}
document := NewBOM("")
hashed, err := document.HashmapVulnerability(cdxVulnerability, nil)
if err != nil {
t.Error(err)
return
}
if !hashed {
t.Error(getLogger().Errorf("expected non-empty vulnerability to be hashed."))
}
}

// ----------------------
// License Hashing
// ----------------------
Expand Down
Loading