Skip to content

Commit

Permalink
fix:Gosec Security Scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Mar 17, 2023
1 parent 35afa41 commit 72ee4f4
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 12 deletions.
9 changes: 8 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,9 +898,12 @@ func (app *TerraApp) LoadHeight(height int64) error {
// ModuleAccountAddrs returns all the app's module account addresses.
func (app *TerraApp) ModuleAccountAddrs() map[string]bool {
modAccAddrs := make(map[string]bool)

/* #nosec */
for acc := range maccPerms {
modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true
}

delete(modAccAddrs, authtypes.NewModuleAddress(alliancetypes.ModuleName).String())

return modAccAddrs
Expand Down Expand Up @@ -952,7 +955,11 @@ func (app *TerraApp) GetMemKey(storeKey string) *storetypes.MemoryStoreKey {
//
// NOTE: This is solely to be used for testing purposes.
func (app *TerraApp) GetSubspace(moduleName string) paramstypes.Subspace {
subspace, _ := app.ParamsKeeper.GetSubspace(moduleName)
subspace, found := app.ParamsKeeper.GetSubspace(moduleName)
if !found {
panic("Module with '" + moduleName + "' name does not exist")
}

return subspace
}

Expand Down
3 changes: 2 additions & 1 deletion app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ func TestSimAppEnforceStakingForVestingTokens(t *testing.T) {

// generate validator private/public key
privVal := mock.NewPV()
pubKey, _ := privVal.GetPubKey()
pubKey, err := privVal.GetPubKey()
require.NoError(t, err, "PubKey should not have an error")
validator := tmtypes.NewValidator(pubKey, 1)
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})

Expand Down
13 changes: 10 additions & 3 deletions app/rpc/error.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package rpc

import (
"net/http"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"net/http"
)

// ErrorResponse defines the attributes of a JSON error response.
Expand All @@ -17,7 +18,10 @@ type ErrorResponse struct {
func WriteErrorResponse(w http.ResponseWriter, status int, err string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
_, _ = w.Write(legacy.Cdc.MustMarshalJSON(NewErrorResponse(0, err)))
_, err1 := w.Write(legacy.Cdc.MustMarshalJSON(NewErrorResponse(0, err)))
if err1 != nil {
panic(err1)
}
}

// NewErrorResponse creates a new ErrorResponse instance.
Expand Down Expand Up @@ -62,5 +66,8 @@ func PostProcessResponseBare(w http.ResponseWriter, ctx client.Context, body int
}

w.Header().Set("Content-Type", "application/json")
_, _ = w.Write(resp)
_, err = w.Write(resp)
if err != nil {
panic(err)
}
}
11 changes: 9 additions & 2 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@ func SetupGenesisValSet(
totalSupply := sdk.NewCoins()

for _, val := range valSet.Validators {
pk, _ := cryptocodec.FromTmPubKeyInterface(val.PubKey)
pkAny, _ := codectypes.NewAnyWithValue(pk)
pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey)
if err != nil {
panic(err)
}

pkAny, err := codectypes.NewAnyWithValue(pk)
if err != nil {
panic(err)
}
validator := stakingtypes.Validator{
OperatorAddress: sdk.ValAddress(val.Address).String(),
ConsensusPubkey: pkAny,
Expand Down
18 changes: 14 additions & 4 deletions cmd/terrad/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"bufio"
"encoding/json"
"fmt"
terraappconfig "github.com/terra-money/core/v2/app/config"
"os"
"path/filepath"

terraappconfig "github.com/terra-money/core/v2/app/config"

"github.com/cosmos/go-bip39"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -81,14 +82,20 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command {
config := serverCtx.Config
config.SetRoot(clientCtx.HomeDir)

chainID, _ := cmd.Flags().GetString(flags.FlagChainID)
chainID, err := cmd.Flags().GetString(flags.FlagChainID)
if err != nil {
return err
}
if chainID == "" {
chainID = fmt.Sprintf("test-chain-%v", tmrand.Str(6))
}

// Get bip39 mnemonic
var mnemonic string
recover, _ := cmd.Flags().GetBool(FlagRecover)
recover, err := cmd.Flags().GetBool(FlagRecover)
if err != nil {
return err
}
if recover {
inBuf := bufio.NewReader(cmd.InOrStdin())
value, err := input.GetString("Enter your bip39 mnemonic", inBuf)
Expand All @@ -110,7 +117,10 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command {
config.Moniker = args[0]

genFile := config.GenesisFile()
overwrite, _ := cmd.Flags().GetBool(FlagOverwrite)
overwrite, err := cmd.Flags().GetBool(FlagOverwrite)
if err != nil {
return err
}

if !overwrite && tmos.FileExists(genFile) {
return fmt.Errorf("genesis.json file already exists: %v", genFile)
Expand Down
2 changes: 1 addition & 1 deletion cmd/terrad/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a
baseapp.SetTrace(cast.ToBool(appOpts.Get(server.FlagTrace))),
baseapp.SetIndexEvents(cast.ToStringSlice(appOpts.Get(server.FlagIndexEvents))),
baseapp.SetSnapshot(snapshotStore, snapshotOptions),
baseapp.SetIAVLCacheSize(int(cast.ToUint64(appOpts.Get(flagIAVLCacheSize)))),
baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(flagIAVLCacheSize))),
)
}

Expand Down

0 comments on commit 72ee4f4

Please sign in to comment.