-
Notifications
You must be signed in to change notification settings - Fork 594
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
many: fix snap set and unset panics on empty strings #14958
many: fix snap set and unset panics on empty strings #14958
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #14958 +/- ##
=========================================
Coverage ? 78.26%
=========================================
Files ? 1160
Lines ? 153488
Branches ? 0
=========================================
Hits ? 120133
Misses ? 25950
Partials ? 7405
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Codecov isn't thrilled, could the new error messages be added to tests in client/clientutil
as well? The consumers certainly test this well enough, though.
@olivercalder done, thanks! |
Fri Jan 24 17:00:57 UTC 2025 Failures:Preparing:
Restoring:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
client/clientutil/config.go
Outdated
@@ -52,6 +53,10 @@ func ParseConfigValues(confValues []string, opts *ParseConfigOptions) (map[strin | |||
parts := strings.SplitN(patchValue, "=", 2) | |||
if len(parts) == 1 && strings.HasSuffix(patchValue, "!") { | |||
key := strings.TrimSuffix(patchValue, "!") | |||
if key == "" { | |||
return nil, nil, errors.New(i18n.G("configuration keys cannot be empty")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we could use a more specific error for !
input:
return nil, nil, errors.New(i18n.G("configuration keys cannot be empty")) | |
return nil, nil, errors.New(i18n.G("configuration keys cannot be empty (want key! to unset a key)")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks!
0b0767e
to
e9e0278
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks
These cases were triggering panics:
These all end up in
config.Transaction.Set
, which callsconfig.PatchConfig
. That function assumes that the parameters that are passed in are valid. In these given cases, the key we're either trying to set or unset is an empty string.I added a check in
config.Transaction.Set
to hopefully prevent this kind of thing in the future, and I added explicit checks on the CLI side to prevent a trip to the daemon in the case that we have invalid parameters.This was reported here: https://forum.snapcraft.io/t/bug-calling-unset-with-empty-string-explodes-snapd/44741