[#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 <leonard@nspcc.ru>
remotes/KirillovDenis/release/v0.21.1
Leonard Lyubich 2021-05-20 11:04:20 +03:00 committed by Alex Vanin
parent 89b147ebe7
commit b2002ffc6d
3 changed files with 3 additions and 13 deletions

View File

@ -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()
}

View File

@ -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
}

View File

@ -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)
}