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(sbom): fix panic when scanning SBOM file without root component into SBOM format #7051

Conversation

DmitriyLewen
Copy link
Contributor

Description

See #7050

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@DmitriyLewen DmitriyLewen self-assigned this Jun 28, 2024
@DmitriyLewen DmitriyLewen marked this pull request as ready for review June 28, 2024 06:33
@DmitriyLewen DmitriyLewen requested a review from knqyf263 as a code owner June 28, 2024 06:34
@@ -86,7 +86,10 @@ func (e *Encoder) rootComponent(r types.Report) (*core.Component, error) {
case artifact.TypeCycloneDX, artifact.TypeSPDX:
// When we scan SBOM file
if r.BOM != nil {
return r.BOM.Root(), nil
// If SBOM file doesn't contain root component - use filesystem
if bomRoot := r.BOM.Root(); bomRoot != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if bomRoot := r.BOM.Root(); bomRoot != nil {
if r.BOM != nil && rBOM.Root() != nil {
return r.BOM.Root(), nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated in c4c413a

Name: "org.apache.logging.log4j:log4j-core",
Version: "2.23.1",
Identifier: ftypes.PkgIdentifier{
UID: "6C0AE96901617503",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it needed? UID is not used in encode.go for now.

Copy link
Contributor Author

@DmitriyLewen DmitriyLewen Jun 28, 2024

Choose a reason for hiding this comment

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

oh.. right. Thanks!
It looks like I accidentally copied Report for testcase from PR where we add UID 😄

Removed in 9afe959

@knqyf263 knqyf263 added this pull request to the merge queue Jun 28, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 28, 2024
@DmitriyLewen DmitriyLewen enabled auto-merge June 28, 2024 09:33
@DmitriyLewen DmitriyLewen added this pull request to the merge queue Jun 28, 2024
Merged via the queue into aquasecurity:main with commit 3d4ae8b Jun 28, 2024
12 checks passed
@DmitriyLewen DmitriyLewen deleted the fix-bom-core/fix-panic-when-there-is-no-root branch June 28, 2024 10:05
skahn007gl pushed a commit to skahn007gl/trivy that referenced this pull request Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(bom): panic when scanning CycloneDX file without metadata.component into SBOM format
2 participants