Skip to content

Commit

Permalink
fix(tests): possible out of range in integration
Browse files Browse the repository at this point in the history
ExpectAllInOrderSequentially might try to access an index out of range
depending on the number of events that are being checked.

More about in issue aquasecurity#4255.
  • Loading branch information
geyslan committed Sep 17, 2024
1 parent d09d7fc commit 15e2612
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/integration/event_filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2469,17 +2469,19 @@ func ExpectAllInOrderSequentially(t *testing.T, cmdEvents []cmdEvents, actual *e

actEvtsCopy := actual.getCopy()

actEvtIdx := 0
// second stage: check events
for cmdIdx, cmd := range cmdEvents {
for _, cmd := range cmdEvents {
syscallsInSets := []string{}
checkSets := len(cmd.sets) > 0
if checkSets {
syscallsInSets = getAllSyscallsInSets(cmd.sets)
}

// compare the expected events with the actual events in the same order
for evtIdx, expEvt := range cmd.expectedEvents {
actEvt := actEvtsCopy[cmdIdx*len(cmd.expectedEvents)+evtIdx]
for _, expEvt := range cmd.expectedEvents {
actEvt := actEvtsCopy[actEvtIdx]
actEvtIdx++

if checkSets && !isInSets(actEvt.EventName, syscallsInSets) {
return fmt.Errorf("Event %s not found in sets %v", actEvt.EventName, cmd.sets)
Expand Down

0 comments on commit 15e2612

Please sign in to comment.