From 4284869199a3e4a3eebd831addf73e82480a552a Mon Sep 17 00:00:00 2001 From: Amit Schendel Date: Thu, 29 Aug 2024 06:47:35 +0000 Subject: [PATCH] Adding a check for nil port Signed-off-by: Amit Schendel --- pkg/ruleengine/v1/r1009_crypto_mining_port.go | 4 ++++ pkg/ruleengine/v1/r1009_crypto_mining_port_test.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/pkg/ruleengine/v1/r1009_crypto_mining_port.go b/pkg/ruleengine/v1/r1009_crypto_mining_port.go index 5c84b3f4..d69f493e 100644 --- a/pkg/ruleengine/v1/r1009_crypto_mining_port.go +++ b/pkg/ruleengine/v1/r1009_crypto_mining_port.go @@ -82,6 +82,10 @@ func (rule *R1009CryptoMiningRelatedPort) ProcessEvent(eventType utils.EventType // Check if the port is in the egress list. for _, nn := range nnContainer.Egress { for _, port := range nn.Ports { + if port.Port == nil { + continue + } + if networkEvent.Port == uint16(*port.Port) { return nil } diff --git a/pkg/ruleengine/v1/r1009_crypto_mining_port_test.go b/pkg/ruleengine/v1/r1009_crypto_mining_port_test.go index 7fa69d98..42bde1ac 100644 --- a/pkg/ruleengine/v1/r1009_crypto_mining_port_test.go +++ b/pkg/ruleengine/v1/r1009_crypto_mining_port_test.go @@ -88,4 +88,12 @@ func TestR1009CryptoMiningRelatedPort(t *testing.T) { t.Errorf("Expected nil, got %v", result) } + // Test with nil port in the egress list + port = 0 + objCache.nn.Spec.Containers[0].Egress[0].Ports[0].Port = &port + result = rule.ProcessEvent(eventType, event, &objCache) + if result == nil { + t.Errorf("Expected not nil, got %v", result) + } + }