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

postgres: return empty map instead of nil #1180

Merged
merged 1 commit into from
Dec 19, 2023

Conversation

RTann
Copy link
Contributor

@RTann RTann commented Dec 14, 2023

All users of this function expect the returned map to be non-nil when the returned error is non-nil. Returning nil, nil causes a panic in libvuln.OfflineImport: https://github.com/quay/claircore/blob/v1.5.20/libvuln/updates.go#L40

There is already another line above this (line 230) which returns out, nil when errors.Is(err, pgx.ErrNoRows). I guess the one that returned nil, nil was a mistake?

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x28b53dd]

goroutine 1 [running]:
github.com/quay/claircore/libvuln.OfflineImport({0x34f75e0?, 0xc0008782d0?}, 0xc00100b0e0, {0x34c55e0?, 0xc00048d000})
	github.com/quay/[email protected]/libvuln/updates.go:40 +0x25d
github.com/stackrox/rox/scanner/matcher/updater.(*Updater).Update(0xc0010c0e40, {0x34f7688?, 0xc0010c6270?})
	github.com/stackrox/rox/scanner/matcher/updater/updater.go:192 +0x42a
github.com/stackrox/rox/scanner/matcher.NewMatcher({0x34f7688?, 0xc000132ed0?}, {{{0xc0000d0370, 0xa8}, {0xc000cd05d0, 0x2c}}, 0x1, {0x0, 0x0}, 0x0})
	github.com/stackrox/rox/scanner/matcher/matcher.go:87 +0x5a5
main.createBackends({0x34f7688, 0xc000132ed0}, 0xc000be20b0)
	github.com/stackrox/rox/scanner/cmd/scanner/main.go:190 +0x347
main.main()
	github.com/stackrox/rox/scanner/cmd/scanner/main.go:80 +0x665

@RTann RTann requested a review from a team as a code owner December 14, 2023 01:59
@RTann RTann requested review from hdonnay and crozzy and removed request for a team December 14, 2023 01:59
Copy link

codecov bot commented Dec 14, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (a2cb548) 52.38% compared to head (9d6b858) 52.36%.

Files Patch % Lines
datastore/postgres/getupdateoperations.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1180      +/-   ##
==========================================
- Coverage   52.38%   52.36%   -0.02%     
==========================================
  Files         221      221              
  Lines       16959    16959              
==========================================
- Hits         8884     8881       -3     
- Misses       7265     7267       +2     
- Partials      810      811       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@RTann RTann changed the title fix(postgres): return empty map instead of nil postgres: return empty map instead of nil Dec 15, 2023
Copy link
Contributor

@crozzy crozzy left a comment

Choose a reason for hiding this comment

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

It seems reasonable that if the err is nil the caller would expect a non-nil value

@RTann RTann force-pushed the ross/fix-offline-update-ops-panic branch from 99ced0a to 9d6b858 Compare December 19, 2023 01:38
@RTann
Copy link
Contributor Author

RTann commented Dec 19, 2023

Will merge with CI

@RTann RTann merged commit 9210797 into quay:main Dec 19, 2023
9 checks passed
@RTann RTann deleted the ross/fix-offline-update-ops-panic branch December 19, 2023 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants