From b84d1cbcc7facac0c97a6f0ed0aa9d3eddc2eade Mon Sep 17 00:00:00 2001 From: Duong Minh Ngoc Date: Tue, 5 Mar 2024 10:51:02 +0700 Subject: [PATCH] fix(claimsmanager): check index to avoid runtime panic --- x/claimsmanager/keeper/grpc_query.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/claimsmanager/keeper/grpc_query.go b/x/claimsmanager/keeper/grpc_query.go index 048ebb7bc..a9f716ee7 100644 --- a/x/claimsmanager/keeper/grpc_query.go +++ b/x/claimsmanager/keeper/grpc_query.go @@ -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 @@ -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