From 5b545107ce694110154d923980bae9fe383050bf Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Mon, 6 Dec 2021 07:07:58 +0100 Subject: [PATCH] Fix potential "out-of-range" crash when translating field expressions --- compose/service/module.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/compose/service/module.go b/compose/service/module.go index b43f3f7fd..01d641d71 100644 --- a/compose/service/module.go +++ b/compose/service/module.go @@ -493,11 +493,11 @@ func (svc module) handleUpdate(ctx context.Context, upd *types.Module) moduleUpd } // Get max validatorID for later use - vvID := make([]uint64, len(res.Fields)) - for i, f := range res.Fields { + vvID := make(map[uint64]uint64) + for _, f := range res.Fields { for _, v := range f.Expressions.Validators { - if vvID[i] < v.ValidatorID { - vvID[i] = v.ValidatorID + if vvID[f.ID] < v.ValidatorID { + vvID[f.ID] = v.ValidatorID } } } @@ -537,11 +537,11 @@ func (svc module) handleUpdate(ctx context.Context, upd *types.Module) moduleUpd } // Assure validatorIDs - for i, f := range res.Fields { + for _, f := range res.Fields { for j, v := range f.Expressions.Validators { if v.ValidatorID == 0 { - vvID[i] += 1 - v.ValidatorID = vvID[i] + vvID[f.ID] += 1 + v.ValidatorID = vvID[f.ID] f.Expressions.Validators[j] = v changes |= moduleFieldsChanged