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

operator/pkg: mitigate null pointer dereference in Validate() and newRunData() functions #5617

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mohamedawnallah
Copy link
Contributor

@mohamedawnallah mohamedawnallah commented Sep 27, 2024

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 in newRunData func and on opt.Karmada.Spec.Components in Validate in init.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?:

NONE

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>
@karmada-bot karmada-bot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Sep 27, 2024
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign poor12 for approval. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot karmada-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Sep 27, 2024
@mohamedawnallah mohamedawnallah changed the title operator/pkg: mitigate null pointer dereference in the functions Validate and newRunData operator/pkg: mitigate null pointer dereference in Validate() and newRunData() functions Sep 27, 2024
@@ -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")
}
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants