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 all commits
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
19 changes: 0 additions & 19 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,6 @@ jobs:
- bin
- profiles

lint:
alessio marked this conversation as resolved.
Show resolved Hide resolved
<<: *linux_defaults
parallelism: 1
steps:
- attach_workspace:
at: /tmp/workspace
- checkout
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Lint source
command: |
export PATH=/tmp/workspace/bin:$PATH
make ci-lint

test_sim_app_nondeterminism:
<<: *linux_defaults
parallelism: 1
Expand Down Expand Up @@ -284,9 +268,6 @@ workflows:
tags:
only:
- /^v.*/
- lint:
requires:
- setup_dependencies
- test_sim_app_nondeterminism:
requires:
- setup_dependencies
Expand Down
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
30 changes: 14 additions & 16 deletions client/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,21 @@ func GetCheckPassword(prompt, prompt2 string, buf *bufio.Reader) (string, error)
// "y", "Y", "yes", "YES", and "Yes" all count as confirmations.
// If the input is not recognized, it returns false and a nil error.
func GetConfirmation(prompt string, buf *bufio.Reader) (bool, error) {
for {
alessio marked this conversation as resolved.
Show resolved Hide resolved
if inputIsTty() {
fmt.Print(fmt.Sprintf("%s [y/N]: ", prompt))
}

response, err := readLineFromBuf(buf)
if err != nil {
return false, err
}

response = strings.ToLower(strings.TrimSpace(response))
if response[0] == 'y' {
return true, nil
}

return false, nil
if inputIsTty() {
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
fmt.Print(fmt.Sprintf("%s [y/N]: ", prompt))
}

response, err := readLineFromBuf(buf)
if err != nil {
return false, err
}

response = strings.ToLower(strings.TrimSpace(response))
if response[0] == 'y' {
return true, nil
}

return false, nil
}

// GetString simply returns the trimmed string output of a given reader.
Expand Down
9 changes: 6 additions & 3 deletions client/rpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,16 @@ func BlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
height, err := strconv.ParseInt(vars["height"], 10, 64)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest,
"ERROR: Couldn't parse block height. Assumed format is '/block/{height}'.")
"couldn't parse block height. Assumed format is '/block/{height}'.")
return
}
chainHeight, err := GetChainHeight(cliCtx)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, "failed to parse chain height")
return
}
if height > chainHeight {
rest.WriteErrorResponse(w, http.StatusNotFound,
"ERROR: Requested block height is bigger then the chain length.")
rest.WriteErrorResponse(w, http.StatusNotFound, "requested block height is bigger then the chain length")
return
}
output, err := getBlock(cliCtx, &height)
Expand Down
8 changes: 6 additions & 2 deletions client/rpc/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,17 @@ func ValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {

height, err := strconv.ParseInt(vars["height"], 10, 64)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, "ERROR: Couldn't parse block height. Assumed format is '/validatorsets/{height}'.")
rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse block height; assumed format is '/validatorsets/{height}'")
return
}

chainHeight, err := GetChainHeight(cliCtx)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, "failed to parse chain height")
return
}
if height > chainHeight {
rest.WriteErrorResponse(w, http.StatusNotFound, "ERROR: Requested block height is bigger then the chain length.")
rest.WriteErrorResponse(w, http.StatusNotFound, "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
7 changes: 5 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 Expand Up @@ -214,3 +215,5 @@ var cdc = codec.New()
func init() {
ctypes.RegisterAmino(cdc)
}

//DONTCOVER
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