From b2002ffc6d2129d3964470d90378662a426f1ae7 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 20 May 2021 11:04:20 +0300 Subject: [PATCH] [#543] object/get: Fix potential NPE on request forwarder Request forwarding callback should be called only if set since it is an optional parameter. In GetRangeHash forwarder is never set. Call `forwarder` function only if it is non-nil. Remove no longer needed `hashOnly` option. Signed-off-by: Leonard Lyubich --- pkg/services/object/get/exec.go | 12 +----------- pkg/services/object/get/get.go | 2 +- pkg/services/object/get/util.go | 2 +- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/pkg/services/object/get/exec.go b/pkg/services/object/get/exec.go index 140ece9f..4752e60b 100644 --- a/pkg/services/object/get/exec.go +++ b/pkg/services/object/get/exec.go @@ -38,7 +38,7 @@ type execCtx struct { curOff uint64 - head, hash bool + head bool curProcEpoch uint64 @@ -71,12 +71,6 @@ func withPayloadRange(r *objectSDK.Range) execOption { } } -func hashOnly() execOption { - return func(c *execCtx) { - c.hash = true - } -} - func (exec *execCtx) setLogger(l *logger.Logger) { req := "GET" if exec.headOnly() { @@ -152,10 +146,6 @@ func (exec *execCtx) headOnly() bool { return exec.head } -func (exec *execCtx) hashOnly() bool { - return exec.hash -} - func (exec *execCtx) netmapEpoch() uint64 { return exec.prm.common.NetmapEpoch() } diff --git a/pkg/services/object/get/get.go b/pkg/services/object/get/get.go index d7f23011..c65bdfe1 100644 --- a/pkg/services/object/get/get.go +++ b/pkg/services/object/get/get.go @@ -41,7 +41,7 @@ func (s *Service) GetRangeHash(ctx context.Context, prm RangeHashPrm) (*RangeHas hash: util.NewSaltingWriter(h, prm.salt), }) - if err := s.getRange(ctx, rngPrm, hashOnly()); err != nil { + if err := s.getRange(ctx, rngPrm); err != nil { return nil, err } diff --git a/pkg/services/object/get/util.go b/pkg/services/object/get/util.go index eb3316de..ba44e595 100644 --- a/pkg/services/object/get/util.go +++ b/pkg/services/object/get/util.go @@ -80,7 +80,7 @@ func (c *clientCacheWrapper) get(addr string) (getClient, error) { } func (c *clientWrapper) getObject(exec *execCtx) (*objectSDK.Object, error) { - if !exec.assembling && !exec.hashOnly() { + if !exec.assembling && exec.prm.forwarder != nil { return exec.prm.forwarder(c.client) }