From 6c08ec9ca24a1db2259155e1611adca8d0b4f1ee Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 12 Apr 2022 16:59:33 +0300 Subject: [PATCH] [#1312] morph/netmap: Fix panic during parameter parsing Signed-off-by: Evgenii Stratonikov --- pkg/morph/client/netmap/config.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/pkg/morph/client/netmap/config.go b/pkg/morph/client/netmap/config.go index 9308152e4..501142635 100644 --- a/pkg/morph/client/netmap/config.go +++ b/pkg/morph/client/netmap/config.go @@ -236,19 +236,19 @@ func WriteConfig(dst ConfigWriter, iterator func(func(key, val []byte) error) er default: dst.UnknownParameter(k, val) case maxObjectSizeConfig: - dst.MaxObjectSize(bigint.FromBytes(val).Uint64()) + dst.MaxObjectSize(bytesToUint64(val)) case basicIncomeRateConfig: - dst.BasicIncomeRate(bigint.FromBytes(val).Uint64()) + dst.BasicIncomeRate(bytesToUint64(val)) case auditFeeConfig: - dst.AuditFee(bigint.FromBytes(val).Uint64()) + dst.AuditFee(bytesToUint64(val)) case epochDurationConfig: - dst.EpochDuration(bigint.FromBytes(val).Uint64()) + dst.EpochDuration(bytesToUint64(val)) case containerFeeConfig: - dst.ContainerFee(bigint.FromBytes(val).Uint64()) + dst.ContainerFee(bytesToUint64(val)) case containerAliasFeeConfig: - dst.ContainerAliasFee(bigint.FromBytes(val).Uint64()) + dst.ContainerAliasFee(bytesToUint64(val)) case etIterationsConfig: - dst.EigenTrustIterations(bigint.FromBytes(val).Uint64()) + dst.EigenTrustIterations(bytesToUint64(val)) case etAlphaConfig: v, err := strconv.ParseFloat(string(val), 64) if err != nil { @@ -257,15 +257,22 @@ func WriteConfig(dst ConfigWriter, iterator func(func(key, val []byte) error) er dst.EigenTrustAlpha(v) case irCandidateFeeConfig: - dst.InnerRingCandidateFee(bigint.FromBytes(val).Uint64()) + dst.InnerRingCandidateFee(bytesToUint64(val)) case withdrawFeeConfig: - dst.WithdrawFee(bigint.FromBytes(val).Uint64()) + dst.WithdrawFee(bytesToUint64(val)) } return nil }) } +func bytesToUint64(val []byte) uint64 { + if len(val) == 0 { + return 0 + } + return bigint.FromBytes(val).Uint64() +} + // config performs the test invoke of get config value // method of NeoFS Netmap contract. func (c *Client) config(key []byte, assert func(stackitem.Item) (interface{}, error)) (interface{}, error) {