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 [email protected]

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

@codecov-commenter
Copy link

codecov-commenter commented Aug 14, 2022

Codecov Report

Attention: Patch coverage is 47.36842% with 10 lines in your changes missing coverage. Please review.

Project coverage is 26.70%. Comparing base (7d80bc0) to head (d12ac3d).
Report is 1167 commits behind head on main.

Files with missing lines Patch % Lines
cmd/cosign/cli/generate/generate_key_pair.go 0.00% 5 Missing ⚠️
cmd/cosign/cli/importkeypair/import_key_pair.go 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2162      +/-   ##
==========================================
+ Coverage   26.23%   26.70%   +0.46%     
==========================================
  Files         130      131       +1     
  Lines        7617     7689      +72     
==========================================
+ Hits         1998     2053      +55     
- Misses       5362     5375      +13     
- Partials      257      261       +4     

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


🚨 Try these New Features:

@dlorenc
Copy link
Member

dlorenc commented Aug 15, 2022

Looks like this needs the boilerplate fix!

Signed-off-by: Samsondeen Dare <[email protected]>
@dsa0x dsa0x force-pushed the fix-panic-key-pair-perm branch from e2e0c47 to 5d2b5d3 Compare August 15, 2022 10:40
@@ -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

@dsa0x dsa0x force-pushed the fix-panic-key-pair-perm branch from 4e3efd0 to 9d30c9e Compare August 17, 2022 07:44
@dsa0x dsa0x requested review from dlorenc and cpanato August 17, 2022 07:47
@dsa0x dsa0x force-pushed the fix-panic-key-pair-perm branch from 9d30c9e to 83d2391 Compare August 17, 2022 10:55
@dsa0x dsa0x force-pushed the fix-panic-key-pair-perm branch from 83d2391 to bf79f0d Compare August 17, 2022 11:37
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 <[email protected]>
Signed-off-by: Samsondeen Dare <[email protected]>
Signed-off-by: Samsondeen Dare <[email protected]>
@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 <[email protected]>

* boilerplate fix

Signed-off-by: Samsondeen Dare <[email protected]>

* move FileExists to internal package

Signed-off-by: Samsondeen Dare <[email protected]>

* remove archived pkg/errors

Signed-off-by: Samsondeen Dare <[email protected]>

* comments

Signed-off-by: Samsondeen Dare <[email protected]>

* comments

Signed-off-by: Samsondeen Dare <[email protected]>

Signed-off-by: Samsondeen Dare <[email protected]>
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.

4 participants