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 nil pointer in patch Apply #7040

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions util/conditions/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ func (p Patch) Apply(latest Setter, options ...ApplyOption) error {

applyOpt := &applyOptions{}
for _, o := range options {
if util.IsNil(o) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a broader issue here about whether we should have nil checks for every arg to every public function for any type that can be nil.

These are the ones we uncovered because this is where the fuzzer touches, but I'm sure there's many more possible cases. I'll open an issue for this to get opinions.

The upside is it will be safer for consumers, but it's going to be messy in the code.

return errors.New("error patching conditions: ApplyOption was nil")
}
o(applyOpt)
}

Expand Down
8 changes: 8 additions & 0 deletions util/conditions/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ func TestApply(t *testing.T) {
want: conditionList(fooFalse), // after condition should be kept in case of error
wantErr: false,
},
{
name: "Error when nil passed as an ApplyOption",
before: getterWithConditions(fooTrue),
after: getterWithConditions(fooFalse),
latest: setterWithConditions(),
options: []ApplyOption{nil},
wantErr: true,
},
}

for _, tt := range tests {
Expand Down