Skip to content

Commit

Permalink
oracle: add length check o.MainCfg.NeoFS.Nodes
Browse files Browse the repository at this point in the history
Prevent the risk of a division by zero error when accessing the
`o.MainCfg.NeoFS.Nodes[index]` array.

Close #3419

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
  • Loading branch information
AliceInHunterland committed May 21, 2024
1 parent dded82f commit 3f8af90
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/services/oracle/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ func (o *Oracle) processRequest(priv *keys.PrivateKey, req request) error {
resp.Code = transaction.Error
}
case neofs.URIScheme:
if len(o.MainCfg.NeoFS.Nodes) == 0 {
o.Log.Warn("No NeoFS nodes configured", zap.String("url", req.Req.URL))
resp.Code = transaction.Error
break

Check warning on line 163 in pkg/services/oracle/request.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/oracle/request.go#L160-L163

Added lines #L160 - L163 were not covered by tests
}
ctx, cancel := context.WithTimeout(context.Background(), o.MainCfg.NeoFS.Timeout)
defer cancel()
index := (int(req.ID) + incTx.attempts) % len(o.MainCfg.NeoFS.Nodes)
Expand Down

0 comments on commit 3f8af90

Please sign in to comment.