From f652518c241f405db22259c753be7f8685f39cc7 Mon Sep 17 00:00:00 2001 From: Ekaterina Lebedeva Date: Fri, 6 Sep 2024 13:09:58 +0300 Subject: [PATCH] [#1357] go: Fix panic caused by using range over slice len If slice is altered in `for` loop, we cannot use range over its length: it may cause panic if slice gets shorter. Signed-off-by: Ekaterina Lebedeva --- pkg/services/control/server/evacuate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/services/control/server/evacuate.go b/pkg/services/control/server/evacuate.go index 300cb9dc9..ae3413373 100644 --- a/pkg/services/control/server/evacuate.go +++ b/pkg/services/control/server/evacuate.go @@ -169,7 +169,7 @@ func (s *Server) getContainerNodes(contID cid.ID) ([]netmap.NodeInfo, error) { nodes := placement.FlattenNodes(ns) bs := (*keys.PublicKey)(&s.key.PublicKey).Bytes() - for i := range len(nodes) { + for i := 0; i < len(nodes); i++ { // don't use range, slice mutates in body if bytes.Equal(nodes[i].PublicKey(), bs) { copy(nodes[i:], nodes[i+1:]) nodes = nodes[:len(nodes)-1] -- 2.45.2