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 panic when os.Stat returns an error besides ErrNotExists #2162

Merged
merged 6 commits into from Aug 17, 2022

Conversation

dsa0x
Copy link
Contributor

@dsa0x dsa0x commented Aug 14, 2022

Signed-off-by: Samsondeen Dare samsondeen.dare@hashicorp.com

Summary

This PR fixes a nil pointer error that occurs when os.Stat returns an error besides ErrNotExist. The issue was also reported in #2161

Release Note

bug fix: fix panic when os.Stat returns an error besides ErrNotExists

Documentation

Signed-off-by: Samsondeen Dare <samsondeen.dare@hashicorp.com>
@codecov-commenter
Copy link

codecov-commenter commented Aug 14, 2022

Codecov Report

Merging #2162 (83d2391) into main (7d80bc0) will increase coverage by 0.47%.
The diff coverage is 47.36%.

@@            Coverage Diff             @@
##             main    #2162      +/-   ##
==========================================
+ Coverage   26.23%   26.70%   +0.47%     
==========================================
  Files         130      131       +1     
  Lines        7617     7688      +71     
==========================================
+ Hits         1998     2053      +55     
- Misses       5362     5374      +12     
- Partials      257      261       +4     
Impacted Files Coverage Δ
cmd/cosign/cli/generate/generate_key_pair.go 8.75% <0.00%> (-0.47%) ⬇️
cmd/cosign/cli/importkeypair/import_key_pair.go 14.58% <0.00%> (-1.33%) ⬇️
pkg/cosign/common.go 0.00% <ø> (ø)
internal/pkg/cosign/common.go 100.00% <100.00%> (ø)
pkg/policy/attestation.go 37.63% <0.00%> (-1.01%) ⬇️
cmd/cosign/cli/fulcio/fulcio.go 18.26% <0.00%> (+0.15%) ⬆️
pkg/cosign/tlog.go 38.55% <0.00%> (+8.48%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@dlorenc
Copy link
Member

dlorenc commented Aug 15, 2022

Looks like this needs the boilerplate fix!

Signed-off-by: Samsondeen Dare <samsondeen.dare@hashicorp.com>
@@ -27,12 +27,15 @@ import (
)

// TODO(jason): Move this to an internal package.
func FileExists(filename string) bool {
func FileExists(filename string) (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

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

What do other semver folks think about this change? It's technically breaking, but I can't find any usage of it on GitHub.

Copy link
Contributor Author

@dsa0x dsa0x Aug 15, 2022

Choose a reason for hiding this comment

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

Good catch. Also, to Jason's (Todo) point, I think this should be in an internal package, as this behaviour doesn't need to be public to users. It's trivial to implement if they need to. That would prevent us from running into issues with breaking semver.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, if we're going to change the interface we might as well move it internal at the same time to prevent future issues. WDYT about making the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I can make a commit to that effect. Thanks

Copy link
Member

Choose a reason for hiding this comment

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

+1

Signed-off-by: Samsondeen Dare <samsondeen.dare@hashicorp.com>
Copy link
Member

@cpanato cpanato left a comment

Choose a reason for hiding this comment

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

small request

cmd/cosign/cli/generate/generate_key_pair.go Outdated Show resolved Hide resolved
cmd/cosign/cli/importkeypair/import_key_pair.go Outdated Show resolved Hide resolved
Signed-off-by: Samsondeen Dare <samsondeen.dare@hashicorp.com>
Signed-off-by: Samsondeen Dare <samsondeen.dare@hashicorp.com>
Signed-off-by: Samsondeen Dare <samsondeen.dare@hashicorp.com>
@dsa0x dsa0x requested a review from cpanato August 17, 2022 14:25
Copy link
Member

@cpanato cpanato left a comment

Choose a reason for hiding this comment

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

lgtm

thanks so much
will defer to @dlorenc for final approval

@dlorenc dlorenc merged commit cb4898b into sigstore:main Aug 17, 2022
@github-actions github-actions bot added this to the v1.11.0 milestone Aug 17, 2022
cldmnky pushed a commit to cldmnky/cosign that referenced this pull request Aug 21, 2022
…e#2162)

* fix panic when os.Stat returns an error besides ErrNotExists

Signed-off-by: Samsondeen Dare <samsondeen.dare@hashicorp.com>

* boilerplate fix

Signed-off-by: Samsondeen Dare <samsondeen.dare@hashicorp.com>

* move FileExists to internal package

Signed-off-by: Samsondeen Dare <samsondeen.dare@hashicorp.com>

* remove archived pkg/errors

Signed-off-by: Samsondeen Dare <samsondeen.dare@hashicorp.com>

* comments

Signed-off-by: Samsondeen Dare <samsondeen.dare@hashicorp.com>

* comments

Signed-off-by: Samsondeen Dare <samsondeen.dare@hashicorp.com>

Signed-off-by: Samsondeen Dare <samsondeen.dare@hashicorp.com>
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.

None yet

4 participants