From 89794f167bdea0b96f968a90e045feb172b8378d Mon Sep 17 00:00:00 2001 From: Mohamed Awnallah Date: Mon, 16 Sep 2024 11:38:34 +0300 Subject: [PATCH] operator/pkg/certs: fix null ptr deref in altnames In this commit, we fix th null pointer dereference issue that happens in altnames mutators for both Karmada APIServer and EtcdServer when accessing the `Components` field on `AltNamesMutatorConfig` struct. Signed-off-by: Mohamed Awnallah --- operator/pkg/certs/certs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/operator/pkg/certs/certs.go b/operator/pkg/certs/certs.go index d58c4db3415a..9b010d53895d 100644 --- a/operator/pkg/certs/certs.go +++ b/operator/pkg/certs/certs.go @@ -455,7 +455,7 @@ func etcdServerAltNamesMutator(cfg *AltNamesMutatorConfig) (*certutil.AltNames, IPs: []net.IP{net.IPv4(127, 0, 0, 1)}, } - if cfg.Components.Etcd.Local != nil { + if cfg.Components != nil && cfg.Components.Etcd != nil && cfg.Components.Etcd.Local != nil { appendSANsToAltNames(altNames, cfg.Components.Etcd.Local.ServerCertSANs) } @@ -488,7 +488,7 @@ func apiServerAltNamesMutator(cfg *AltNamesMutatorConfig) (*certutil.AltNames, e fmt.Sprintf("*.%s.svc", cfg.Namespace)}) } - if len(cfg.Components.KarmadaAPIServer.CertSANs) > 0 { + if cfg.Components != nil && cfg.Components.KarmadaAPIServer != nil && len(cfg.Components.KarmadaAPIServer.CertSANs) > 0 { appendSANsToAltNames(altNames, cfg.Components.KarmadaAPIServer.CertSANs) } if len(cfg.ControlplaneAddress) > 0 {