Skip to content

Commit

Permalink
gosec fix: made changes based on gosec analyzer results
Browse files Browse the repository at this point in the history
  • Loading branch information
arnabghose997 committed Nov 25, 2023
1 parent c863a58 commit 7197f3c
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gosec.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Gosec
name: Gosec
on:
pull_request:

Expand Down
4 changes: 2 additions & 2 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ func (app *HidnodeApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddr
iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
counter := int16(0)

defer iter.Close()

for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Key()[1:])
validator, found := app.StakingKeeper.GetValidator(ctx, addr)
Expand All @@ -166,8 +168,6 @@ func (app *HidnodeApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddr
counter++
}

iter.Close()

if _, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx); err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/hid-noded/cmd/debug_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"crypto/ed25519"
"crypto/rand"
"crypto/rand" /* #nosec G702 */
"crypto/sha256"
"encoding/base64"
"encoding/hex"
Expand Down
2 changes: 1 addition & 1 deletion x/ssi/ante/decorators.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (mfd MempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b

// Determine the required fees by multiplying each required minimum gas
// price by the gas limit, where fee = ceil(minGasPrice * gasLimit).
glDec := sdk.NewDec(int64(gas))
glDec := sdk.NewDec(int64(gas)) /* #nosec G701 */
for i, gp := range minGasPrices {
fee := gp.Amount.Mul(glDec)
requiredFees[i] = sdk.NewCoin(gp.Denom, fee.Ceil().RoundInt())
Expand Down
5 changes: 4 additions & 1 deletion x/ssi/keeper/msg_server_create_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ func (k msgServer) RegisterCredentialStatus(goCtx context.Context, msg *types.Ms
}

// Check if the created date before issuance date
currentDate, _ := time.Parse(time.RFC3339, msgCredProof.Created)
currentDate, err := time.Parse(time.RFC3339, msgCredProof.Created)
if err != nil {
return nil, err
}
if currentDate.Before(issuanceDateParsed) {
return nil, sdkerrors.Wrapf(types.ErrInvalidDate, "proof attached has a creation date before issuance date")
}
Expand Down
7 changes: 5 additions & 2 deletions x/ssi/keeper/msg_server_update_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keeper
import (
"context"
"fmt"
"reflect"
"reflect" /* #nosec G702 */
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -89,7 +89,10 @@ func (k msgServer) UpdateCredentialStatus(goCtx context.Context, msg *types.MsgU
}

// Check if the created date before issuance date
currentDate, _ := time.Parse(time.RFC3339, msgNewCredProof.Created)
currentDate, err := time.Parse(time.RFC3339, msgNewCredProof.Created)
if err != nil {
return nil, err
}
if currentDate.Before(newIssuanceDateParsed) {
return nil, sdkerrors.Wrapf(types.ErrInvalidDate, "proof attached has a creation date before issuance date")
}
Expand Down
2 changes: 1 addition & 1 deletion x/ssi/keeper/msg_server_update_did.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keeper
import (
"context"
"fmt"
"reflect"
"reflect" /* #nosec G702 */

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down
5 changes: 4 additions & 1 deletion x/ssi/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ func DefaultGenesis() *GenesisState {
func (gs GenesisState) Validate() error {
namespace := gs.ChainNamespace

regexPattern, _ := regexp.Compile("^[a-zA-Z0-9-]*$") // Matches string containing whitespaces and tabs
regexPattern, err := regexp.Compile("^[a-zA-Z0-9-]*$") // Matches string containing whitespaces and tabs
if err != nil {
return err
}
maxChainNamespaceLength := 10

if len(namespace) > maxChainNamespaceLength {
Expand Down

0 comments on commit 7197f3c

Please sign in to comment.