Skip to content

Commit

Permalink
Adding a check for nil port
Browse files Browse the repository at this point in the history
Signed-off-by: Amit Schendel <amitschendel@gmail.com>
  • Loading branch information
amitschendel committed Aug 29, 2024
1 parent fe5e5b8 commit 4284869
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/ruleengine/v1/r1009_crypto_mining_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/ruleengine/v1/r1009_crypto_mining_port_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}

0 comments on commit 4284869

Please sign in to comment.