Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More linters - Gosec, staticcheck #4608

Merged
merged 10 commits into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ linters:
- misspell
- govet
- goconst
- gosec
- staticcheck
linters-settings:
gocyclo:
min-complexity: 11
Expand Down
4 changes: 2 additions & 2 deletions client/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ func GetConfirmation(prompt string, buf *bufio.Reader) (bool, error) {
response = strings.ToLower(strings.TrimSpace(response))
if response[0] == 'y' {
return true, nil
} else {
return false, nil
}

return false, nil
}
}

Expand Down
5 changes: 5 additions & 0 deletions client/rpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ func BlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return
}
chainHeight, err := GetChainHeight(cliCtx)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest,
"ERROR: Could not recieve chain height. ")
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
return
}
if height > chainHeight {
rest.WriteErrorResponse(w, http.StatusNotFound,
"ERROR: Requested block height is bigger then the chain length.")
Expand Down
5 changes: 5 additions & 0 deletions client/rpc/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ func ValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
}

chainHeight, err := GetChainHeight(cliCtx)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest,
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
"ERROR: Could not recieve chain height.")
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
return
}
if height > chainHeight {
rest.WriteErrorResponse(w, http.StatusNotFound, "ERROR: Requested block height is bigger then the chain length.")
return
Expand Down
2 changes: 1 addition & 1 deletion server/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// Get a free address for a test tendermint server
// protocol is either tcp, http, etc
func FreeTCPAddr() (addr, port string, err error) {
l, err := net.Listen("tcp", "0.0.0.0:0")
l, err := net.Listen("tcp", "localhost:0")
if err != nil {
return "", "", err
}
Expand Down
3 changes: 3 additions & 0 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ func interceptLoadConfig() (conf *cfg.Config, err error) {

if conf == nil {
conf, err = tcmd.ParseConfig() // NOTE: ParseConfig() creates dir/files as necessary.
if err != nil {
panic("err")
}
}

appConfigFilePath := filepath.Join(rootDir, "config/app.toml")
Expand Down
2 changes: 0 additions & 2 deletions simapp/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []str
iter := sdk.KVStoreReversePrefixIterator(store, staking.ValidatorsKey)
counter := int16(0)

var valConsAddrs []sdk.ConsAddress
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Key()[1:])
validator, found := app.stakingKeeper.GetValidator(ctx, addr)
Expand All @@ -142,7 +141,6 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []str
}

validator.UnbondingHeight = 0
valConsAddrs = append(valConsAddrs, validator.ConsAddress())
if applyWhiteList && !whiteListMap[addr.String()] {
validator.Jailed = true
}
Expand Down
5 changes: 3 additions & 2 deletions tests/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ func waitForHeight(height int64, url string) {
var res *http.Response
var err error
for {
res, err = http.Get(url)
// Since this is in a testing file we are accepting nolint to be passed
res, err = http.Get(url) //nolint:gosec
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -150,7 +151,7 @@ func WaitForStart(url string) {
time.Sleep(time.Millisecond * 100)

var res *http.Response
res, err = http.Get(url)
res, err = http.Get(url) //nolint:gosec Error is arising in testing files, accepting nolint
if err != nil || res == nil {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion x/genutil/client/cli/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ func readUnsignedGenTxFile(cdc *codec.Codec, r io.Reader) (auth.StdTx, error) {

func writeSignedGenTx(cdc *codec.Codec, outputDocument string, tx auth.StdTx) error {
outputFile, err := os.OpenFile(outputDocument, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644)
defer outputFile.Close()
if err != nil {
return err
}
defer outputFile.Close()
json, err := cdc.MarshalJSON(tx)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion x/gov/simulation/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func operationSimulateMsgVote(k gov.Keeper, acc simulation.Account, proposalID u
acc = simulation.RandomAcc(r, accs)
}

if proposalID < 0 {
if proposalID < uint64(0) {
var ok bool
proposalID, ok = randomProposalID(r, k, ctx)
if !ok {
Expand Down
5 changes: 5 additions & 0 deletions x/staking/client/rest/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func queryBonds(cliCtx context.CLIContext, endpoint string) http.HandlerFunc {
bech32validator := vars["validatorAddr"]

delegatorAddr, err := sdk.AccAddressFromBech32(bech32delegator)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

validatorAddr, err := sdk.ValAddressFromBech32(bech32validator)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
Expand Down