From ba6bd4960eb5f2d3fec214ac51868ea73a7a7e42 Mon Sep 17 00:00:00 2001 From: Youngtaek Yoon Date: Wed, 24 Jan 2024 03:48:27 +0000 Subject: [PATCH] Gosec --- x/foundation/keeper/internal/censorship.go | 16 +++++++++++---- x/foundation/keeper/internal/member.go | 12 ++++++++--- .../keeper/internal/migrations/v2/store.go | 4 +++- x/foundation/keeper/internal/proposal.go | 20 ++++++++++++++----- x/foundation/keeper/internal/treasury.go | 4 +++- x/foundation/keeper/internal/vote.go | 8 ++++++-- 6 files changed, 48 insertions(+), 16 deletions(-) diff --git a/x/foundation/keeper/internal/censorship.go b/x/foundation/keeper/internal/censorship.go index 23b212695c..240836f5ed 100644 --- a/x/foundation/keeper/internal/censorship.go +++ b/x/foundation/keeper/internal/censorship.go @@ -56,12 +56,16 @@ func (k Keeper) SetCensorship(ctx sdk.Context, censorship foundation.Censorship) key := censorshipKey(censorship.MsgTypeUrl) if censorship.Authority == foundation.CensorshipAuthorityUnspecified { - store.Delete(key) + if err := store.Delete(key); err != nil { + panic(err) + } return } bz := k.cdc.MustMarshal(&censorship) - store.Set(key, bz) + if err := store.Set(key, bz); err != nil { + panic(err) + } } func (k Keeper) iterateCensorships(ctx sdk.Context, fn func(censorship foundation.Censorship) (stop bool)) { @@ -186,13 +190,17 @@ func (k Keeper) setAuthorization(ctx sdk.Context, grantee sdk.AccAddress, author if err != nil { panic(err) } - store.Set(key, bz) + if err := store.Set(key, bz); err != nil { + panic(err) + } } func (k Keeper) deleteAuthorization(ctx sdk.Context, grantee sdk.AccAddress, msgTypeURL string) { store := k.storeService.OpenKVStore(ctx) key := grantKey(grantee, msgTypeURL) - store.Delete(key) + if err := store.Delete(key); err != nil { + panic(err) + } } func (k Keeper) Accept(ctx sdk.Context, grantee sdk.AccAddress, msg sdk.Msg) error { diff --git a/x/foundation/keeper/internal/member.go b/x/foundation/keeper/internal/member.go index 3066fa23c2..b669952608 100644 --- a/x/foundation/keeper/internal/member.go +++ b/x/foundation/keeper/internal/member.go @@ -57,7 +57,9 @@ func (k Keeper) GetFoundationInfo(ctx sdk.Context) foundation.FoundationInfo { func (k Keeper) SetFoundationInfo(ctx sdk.Context, info foundation.FoundationInfo) { store := k.storeService.OpenKVStore(ctx) bz := k.cdc.MustMarshal(&info) - store.Set(foundationInfoKey, bz) + if err := store.Set(foundationInfoKey, bz); err != nil { + panic(err) + } } func (k Keeper) UpdateMembers(ctx sdk.Context, members []foundation.MemberRequest) error { @@ -137,13 +139,17 @@ func (k Keeper) SetMember(ctx sdk.Context, member foundation.Member) { key := memberKey(addr) bz := k.cdc.MustMarshal(&member) - store.Set(key, bz) + if err := store.Set(key, bz); err != nil { + panic(err) + } } func (k Keeper) deleteMember(ctx sdk.Context, address sdk.AccAddress) { store := k.storeService.OpenKVStore(ctx) key := memberKey(address) - store.Delete(key) + if err := store.Delete(key); err != nil { + panic(err) + } } func (k Keeper) iterateMembers(ctx sdk.Context, fn func(member foundation.Member) (stop bool)) { diff --git a/x/foundation/keeper/internal/migrations/v2/store.go b/x/foundation/keeper/internal/migrations/v2/store.go index 031e151f87..8f7c512fde 100644 --- a/x/foundation/keeper/internal/migrations/v2/store.go +++ b/x/foundation/keeper/internal/migrations/v2/store.go @@ -31,7 +31,9 @@ func migrateParams(ctx sdk.Context, store store.KVStore, cdc codec.BinaryCodec, if bz == nil { return fmt.Errorf("params not found") } - store.Delete(ParamsKey) + if err := store.Delete(ParamsKey); err != nil { + return err + } var params foundation.Params if err := cdc.Unmarshal(bz, ¶ms); err != nil { diff --git a/x/foundation/keeper/internal/proposal.go b/x/foundation/keeper/internal/proposal.go index 3d3d342f4e..254360e427 100644 --- a/x/foundation/keeper/internal/proposal.go +++ b/x/foundation/keeper/internal/proposal.go @@ -33,7 +33,9 @@ func (k Keeper) getPreviousProposalID(ctx sdk.Context) uint64 { func (k Keeper) setPreviousProposalID(ctx sdk.Context, id uint64) { store := k.storeService.OpenKVStore(ctx) - store.Set(previousProposalIDKey, Uint64ToBytes(id)) + if err := store.Set(previousProposalIDKey, Uint64ToBytes(id)); err != nil { + panic(err) + } } func (k Keeper) SubmitProposal(ctx sdk.Context, proposers []string, metadata string, msgs []sdk.Msg) (*uint64, error) { @@ -230,25 +232,33 @@ func (k Keeper) setProposal(ctx sdk.Context, proposal foundation.Proposal) { key := proposalKey(proposal.Id) bz := k.cdc.MustMarshal(&proposal) - store.Set(key, bz) + if err := store.Set(key, bz); err != nil { + panic(err) + } } func (k Keeper) deleteProposal(ctx sdk.Context, proposalID uint64) { store := k.storeService.OpenKVStore(ctx) key := proposalKey(proposalID) - store.Delete(key) + if err := store.Delete(key); err != nil { + panic(err) + } } func (k Keeper) addProposalToVPEndQueue(ctx sdk.Context, proposal foundation.Proposal) { store := k.storeService.OpenKVStore(ctx) key := proposalByVPEndKey(proposal.VotingPeriodEnd, proposal.Id) - store.Set(key, []byte{}) + if err := store.Set(key, []byte{}); err != nil { + panic(err) + } } func (k Keeper) removeProposalFromVPEndQueue(ctx sdk.Context, proposal foundation.Proposal) { store := k.storeService.OpenKVStore(ctx) key := proposalByVPEndKey(proposal.VotingPeriodEnd, proposal.Id) - store.Delete(key) + if err := store.Delete(key); err != nil { + panic(err) + } } func validateActorForProposal(address string, proposal foundation.Proposal) error { diff --git a/x/foundation/keeper/internal/treasury.go b/x/foundation/keeper/internal/treasury.go index 18c0508fac..22928d7e44 100644 --- a/x/foundation/keeper/internal/treasury.go +++ b/x/foundation/keeper/internal/treasury.go @@ -75,5 +75,7 @@ func (k Keeper) SetPool(ctx sdk.Context, pool foundation.Pool) { store := k.storeService.OpenKVStore(ctx) key := poolKey - store.Set(key, bz) + if err := store.Set(key, bz); err != nil { + panic(err) + } } diff --git a/x/foundation/keeper/internal/vote.go b/x/foundation/keeper/internal/vote.go index cc3296a448..804b9dbcd2 100644 --- a/x/foundation/keeper/internal/vote.go +++ b/x/foundation/keeper/internal/vote.go @@ -83,7 +83,9 @@ func (k Keeper) setVote(ctx sdk.Context, vote foundation.Vote) { key := voteKey(vote.ProposalId, voter) bz := k.cdc.MustMarshal(&vote) - store.Set(key, bz) + if err := store.Set(key, bz); err != nil { + panic(err) + } } func (k Keeper) iterateVotes(ctx sdk.Context, proposalID uint64, fn func(vote foundation.Vote) (stop bool)) { @@ -127,6 +129,8 @@ func (k Keeper) pruneVotes(ctx sdk.Context, proposalID uint64) { store := k.storeService.OpenKVStore(ctx) for _, key := range keys { - store.Delete(key) + if err := store.Delete(key); err != nil { + panic(err) + } } }