Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@frenchi
Copy link
Contributor

@frenchi frenchi commented Jan 25, 2023

It is possible to cause a segfault by providing invalid json.

./sbom-scorecard score ../../examples/invalid.json                                                       ⏎ ✹ ✭
Guessed: cdx
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x11acab8]

goroutine 1 [running]:
github.com/ebay/sbom-scorecard/pkg/cdx.GetCycloneDXReport({0x7ff7bfeff647, 0x1b})
	.../sbom-scorecard/pkg/cdx/cdx_report.go:119 +0x2f8
github.com/ebay/sbom-scorecard/cmd/sbom-scorecard/cmd.glob..func1(0x13fef00?, {0xc000063930?, 0x1?, 0x1?})
	.../sbom-scorecard/cmd/sbom-scorecard/cmd/scorecard.go:70 +0x1c8
github.com/spf13/cobra.(*Command).execute(0x13fef00, {0xc0000638f0, 0x1, 0x1})
	.../github.com/spf13/[email protected]/command.go:920 +0x847
github.com/spf13/cobra.(*Command).ExecuteC(0x13fec20)
	.../github.com/spf13/[email protected]/command.go:1044 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
	.../github.com/spf13/[email protected]/command.go:968
github.com/ebay/sbom-scorecard/cmd/sbom-scorecard/cmd.Execute()
	.../sbom-scorecard/cmd/sbom-scorecard/cmd/root.go:20 +0x25
main.main()
	.../sbom-scorecard/cmd/sbom-scorecard/main.go:8 +0x17

pkg/cdx/cdx_report.go#L127
Fix nil pointer reference in bom.Metadata.Tools which causes nil pointer segfault when an invalid json file is provided.

pkg/cdx/cdx_report.go#L65
Fix NaN handling leading to invalid score results when an invalid json file is provided.

The root of this issue is likely that upstream cyclonedx-go/blob/master/decode.go#L43 uses json.Decode (which accepts a stream) instead of json.Marshal.

nit: ioutil package deprecated: As of Go 1.16, this function simply calls os.ReadFile.

ioutil package deprecated: As of Go 1.16, this function simply calls os.ReadFile.

Fix nil pointer reference in bom.Metadata.Tools
Copy link
Contributor

@justinabrahms justinabrahms left a comment

Choose a reason for hiding this comment

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

build is failing, fyi.

@frenchi
Copy link
Contributor Author

frenchi commented Jan 29, 2023

So I believe the tests are failing because the underlying logic for cdx_report.go#L49 IsSpecCompliant() is erroneous, as opposed to the test being incorrect.

This is because of an issue in cdx_report.go#L105 GetCycloneDXReport(), decoder.Decode(bom) will never throw err.

@justinabrahms
Copy link
Contributor

Okay. So this no longer segfaults, but it does give weird results. There's an assumption that cyclonedx would return an error if given invalid json. It didn't. I've just made CycloneDX/cyclonedx-go#84 which addresses that upstream. That should cause it to fail with a 0 for a score when they release & we update our dependency.

So sorry for the delay in addressing this.

@justinabrahms justinabrahms merged commit 910a0c8 into eBay:main Apr 10, 2023
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.

2 participants