Skip to content

Commit

Permalink
pkg/k8s: fix invalid memory address or nil pointer dereference
Browse files Browse the repository at this point in the history
Since k8sMeta might return nil, we should check for it before accessing
the fields of that structure otherwise we will risk on panic for a nil
pointer dereference.

Fixes: 63c0b29 ("Checks k8s metadata for pod before removing IP from ipccahe")
Signed-off-by: André Martins <andre@cilium.io>
  • Loading branch information
aanm committed Oct 19, 2021
1 parent b195361 commit 5c0df24
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/k8s/watchers/cilium_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (k *K8sWatcher) endpointDeleted(endpoint *types.CiliumEndpoint) {
for _, pair := range endpoint.Networking.Addressing {
if pair.IPV4 != "" {
k8sMeta := ipcache.IPIdentityCache.GetK8sMetadata(pair.IPV4)
if k8sMeta.Namespace == endpoint.Namespace && k8sMeta.PodName == endpoint.Name {
if k8sMeta != nil && k8sMeta.Namespace == endpoint.Namespace && k8sMeta.PodName == endpoint.Name {
portsChanged := ipcache.IPIdentityCache.Delete(pair.IPV4, source.CustomResource)
if portsChanged {
namedPortsChanged = true
Expand All @@ -221,7 +221,7 @@ func (k *K8sWatcher) endpointDeleted(endpoint *types.CiliumEndpoint) {

if pair.IPV6 != "" {
k8sMeta := ipcache.IPIdentityCache.GetK8sMetadata(pair.IPV6)
if k8sMeta.Namespace == endpoint.Namespace && k8sMeta.PodName == endpoint.Name {
if k8sMeta != nil && k8sMeta.Namespace == endpoint.Namespace && k8sMeta.PodName == endpoint.Name {
portsChanged := ipcache.IPIdentityCache.Delete(pair.IPV6, source.CustomResource)
if portsChanged {
namedPortsChanged = true
Expand Down

0 comments on commit 5c0df24

Please sign in to comment.