-
Notifications
You must be signed in to change notification settings - Fork 883
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
operator/pkg: mitigate null pointer dereference in Validate()
and newRunData()
functions
#5617
base: master
Are you sure you want to change the base?
Conversation
In this commit, we mitigate the null pointer dereference issue in the deinit operator pkg by adding defensive checks on `opt.Karmada.Spec.HostCluster` in `newRunData` func and on `opt.Karmada.Spec.Components` in `Validate` in `init.go`. Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Validate
and newRunData
Validate()
and newRunData()
functions
@@ -65,6 +65,9 @@ func (opt *InitOptions) Validate() error { | |||
return fmt.Errorf("unexpected invalid crds remote url %s", opt.CRDTarball.HTTPSource.URL) | |||
} | |||
} | |||
if opt.Karmada == nil || opt.Karmada.Spec.Components == nil || opt.Karmada.Spec.Components.KarmadaAPIServer == nil { | |||
return fmt.Errorf("invalid Karmada configuration: Karmada, Karmada components, and Karmada API server must be defined") | |||
} |
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.
opt.Karmada.Spec.Components == nil
I'm curious why components are not allowed to be nil. From the API, it seems all fields are optional.
Do you know some background? @chaosi-zju
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.
I'm eager to move this PR forward. Since I'm new to this part of the codebase, I want to make sure I've understood everything correctly. Any additional hints would be greatly appreciated. Thanks! 🙏
Description
In this commit, we mitigate the null pointer dereference issue in the deinit operator pkg by adding defensive checks on
opt.Karmada.Spec.HostCluster
innewRunData
func and onopt.Karmada.Spec.Components
inValidate
ininit.go
.Motivation and Context
While unit testing the Karmada Init and DeInit in the operator package (#5613), deliberately passing empty components on those fields triggers a null pointer exception error. This PR resolves this issue by adding defensive checks.
While testing
What type of PR is this?
/kind cleanup
Does this PR introduce a user-facing change?: