Skip to content

Commit

Permalink
fix(claimsmanager): check index to avoid runtime panic
Browse files Browse the repository at this point in the history
  • Loading branch information
Duong Minh Ngoc committed Mar 5, 2024
1 parent 62f89c9 commit b84d1cb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions x/claimsmanager/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (k Keeper) UserClaims(c context.Context, q *types.QueryClaimsRequest) (*typ
// check for the presence of the addr bytes in the key.
// first prefix byte is 0x00; so cater for that! Then + 1 to skip the separator.
idx := bytes.Index(key[1:], []byte{0x00}) + 1 + 1
if bytes.Equal(key[idx:idx+len(addrBytes)], addrBytes) {
if idx >= 0 && bytes.Equal(key[idx:idx+len(addrBytes)], addrBytes) {
out = append(out, claim)
}
return false
Expand All @@ -88,7 +88,7 @@ func (k Keeper) UserLastEpochClaims(c context.Context, q *types.QueryClaimsReque
// check for the presence of the addr bytes in the key.
// First byte is 0x01 here, so no need to consider it; + 1 to skip the separator.
idx := bytes.Index(key, []byte{0x00}) + 1
if bytes.Equal(key[idx:idx+len(addrBytes)], addrBytes) {
if idx >= 0 && bytes.Equal(key[idx:idx+len(addrBytes)], addrBytes) {
out = append(out, claim)
}
return false
Expand Down

0 comments on commit b84d1cb

Please sign in to comment.