diff --git a/cmd/tendermint/commands/gen_validator.go b/cmd/tendermint/commands/gen_validator.go index 984176d2a..59fe30128 100644 --- a/cmd/tendermint/commands/gen_validator.go +++ b/cmd/tendermint/commands/gen_validator.go @@ -19,7 +19,10 @@ var GenValidatorCmd = &cobra.Command{ func genValidator(cmd *cobra.Command, args []string) { privValidator := types.GenPrivValidatorFS("") - privValidatorJSONBytes, _ := json.MarshalIndent(privValidator, "", "\t") + privValidatorJSONBytes, err := json.MarshalIndent(privValidator, "", "\t") + if err != nil { + panic(err) + } fmt.Printf(`%v `, string(privValidatorJSONBytes)) } diff --git a/consensus/replay_file.go b/consensus/replay_file.go index 4d5a631dc..ba7b12654 100644 --- a/consensus/replay_file.go +++ b/consensus/replay_file.go @@ -59,7 +59,7 @@ func (cs *ConsensusState) ReplayFile(file string, console bool) error { defer cs.eventBus.Unsubscribe(ctx, subscriber, types.EventQueryNewRoundStep) // just open the file for reading, no need to use wal - fp, err := os.OpenFile(file, os.O_RDONLY, 0666) + fp, err := os.OpenFile(file, os.O_RDONLY, 0600) if err != nil { return err } @@ -130,7 +130,7 @@ func (pb *playback) replayReset(count int, newStepCh chan interface{}) error { if err := pb.fp.Close(); err != nil { return err } - fp, err := os.OpenFile(pb.fileName, os.O_RDONLY, 0666) + fp, err := os.OpenFile(pb.fileName, os.O_RDONLY, 0600) if err != nil { return err } diff --git a/node/node.go b/node/node.go index 2de87b1ea..def313943 100644 --- a/node/node.go +++ b/node/node.go @@ -430,7 +430,10 @@ func (n *Node) startRPC() ([]net.Listener, error) { mux := http.NewServeMux() rpcLogger := n.Logger.With("module", "rpc-server") onDisconnect := rpcserver.OnDisconnect(func(remoteAddr string) { - n.eventBus.UnsubscribeAll(context.Background(), remoteAddr) + err := n.eventBus.UnsubscribeAll(context.Background(), remoteAddr) + if err != nil { + rpcLogger.Error("Error unsubsribing from all on disconnect", "err", err) + } }) wm := rpcserver.NewWebsocketManager(rpccore.Routes, onDisconnect) wm.SetLogger(rpcLogger.With("protocol", "websocket")) diff --git a/p2p/fuzz.go b/p2p/fuzz.go index dfa34fa1d..fa16e4a26 100644 --- a/p2p/fuzz.go +++ b/p2p/fuzz.go @@ -124,7 +124,7 @@ func (fc *FuzzedConnection) SetWriteDeadline(t time.Time) error { func (fc *FuzzedConnection) randomDuration() time.Duration { maxDelayMillis := int(fc.config.MaxDelay.Nanoseconds() / 1000) - return time.Millisecond * time.Duration(rand.Int()%maxDelayMillis) + return time.Millisecond * time.Duration(rand.Int()%maxDelayMillis) // nolint: gas } // implements the fuzz (delay, kill conn) @@ -143,7 +143,7 @@ func (fc *FuzzedConnection) fuzz() bool { } else if r < fc.config.ProbDropRW+fc.config.ProbDropConn { // XXX: can't this fail because machine precision? // XXX: do we need an error? - fc.Close() // nolint: errcheck + fc.Close() // nolint: errcheck, gas return true } else if r < fc.config.ProbDropRW+fc.config.ProbDropConn+fc.config.ProbSleep { time.Sleep(fc.randomDuration()) diff --git a/p2p/pex_reactor.go b/p2p/pex_reactor.go index 71c3beb0d..73bb9e75e 100644 --- a/p2p/pex_reactor.go +++ b/p2p/pex_reactor.go @@ -283,7 +283,7 @@ func (r *PEXReactor) ensurePeers() { // If we need more addresses, pick a random peer and ask for more. if r.book.NeedMoreAddrs() { if peers := r.Switch.Peers().List(); len(peers) > 0 { - i := rand.Int() % len(peers) + i := rand.Int() % len(peers) // nolint: gas peer := peers[i] r.Logger.Info("No addresses to dial. Sending pexRequest to random peer", "peer", peer) r.RequestPEX(peer) diff --git a/p2p/secret_connection.go b/p2p/secret_connection.go index 1e9bffc54..aec0a7519 100644 --- a/p2p/secret_connection.go +++ b/p2p/secret_connection.go @@ -302,7 +302,7 @@ func shareAuthSignature(sc *SecretConnection, pubKey crypto.PubKeyEd25519, signa // sha256 func hash32(input []byte) (res *[32]byte) { hasher := sha256.New() - hasher.Write(input) // nolint: errcheck + hasher.Write(input) // nolint: errcheck, gas resSlice := hasher.Sum(nil) res = new([32]byte) copy(res[:], resSlice) @@ -312,7 +312,7 @@ func hash32(input []byte) (res *[32]byte) { // We only fill in the first 20 bytes with ripemd160 func hash24(input []byte) (res *[24]byte) { hasher := ripemd160.New() - hasher.Write(input) // nolint: errcheck + hasher.Write(input) // nolint: errcheck, gas resSlice := hasher.Sum(nil) res = new([24]byte) copy(res[:], resSlice) diff --git a/p2p/trust/trustmetric.go b/p2p/trust/trustmetric.go index cbc2db7d5..c6740c0da 100644 --- a/p2p/trust/trustmetric.go +++ b/p2p/trust/trustmetric.go @@ -47,7 +47,9 @@ func NewTrustMetricStore(db dbm.DB, tmc TrustMetricConfig) *TrustMetricStore { // OnStart implements Service func (tms *TrustMetricStore) OnStart() error { - tms.BaseService.OnStart() + if err := tms.BaseService.OnStart(); err != nil { + return err + } tms.mtx.Lock() defer tms.mtx.Unlock() diff --git a/p2p/types.go b/p2p/types.go index 1d3770b57..4e0994b71 100644 --- a/p2p/types.go +++ b/p2p/types.go @@ -55,12 +55,12 @@ func (info *NodeInfo) CompatibleWith(other *NodeInfo) error { } func (info *NodeInfo) ListenHost() string { - host, _, _ := net.SplitHostPort(info.ListenAddr) + host, _, _ := net.SplitHostPort(info.ListenAddr) // nolint: errcheck, gas return host } func (info *NodeInfo) ListenPort() int { - _, port, _ := net.SplitHostPort(info.ListenAddr) + _, port, _ := net.SplitHostPort(info.ListenAddr) // nolint: errcheck, gas port_i, err := strconv.Atoi(port) if err != nil { return -1 diff --git a/p2p/util.go b/p2p/util.go index 2b85a6cdb..a4c3ad58b 100644 --- a/p2p/util.go +++ b/p2p/util.go @@ -7,9 +7,9 @@ import ( // doubleSha256 calculates sha256(sha256(b)) and returns the resulting bytes. func doubleSha256(b []byte) []byte { hasher := sha256.New() - hasher.Write(b) // nolint: errcheck + hasher.Write(b) // nolint: errcheck, gas sum := hasher.Sum(nil) hasher.Reset() - hasher.Write(sum) // nolint: errcheck + hasher.Write(sum) // nolint: errcheck, gas return hasher.Sum(nil) } diff --git a/rpc/lib/server/handlers.go b/rpc/lib/server/handlers.go index 98825be54..2e24195dc 100644 --- a/rpc/lib/server/handlers.go +++ b/rpc/lib/server/handlers.go @@ -99,7 +99,11 @@ func funcReturnTypes(f interface{}) []reflect.Type { // jsonrpc calls grab the given method's function info and runs reflect.Call func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - b, _ := ioutil.ReadAll(r.Body) + b, err := ioutil.ReadAll(r.Body) + if err != nil { + WriteRPCResponseHTTP(w, types.RPCInvalidRequestError("", errors.Wrap(err, "Error reading request body"))) + return + } // if its an empty request (like from a browser), // just display a list of functions if len(b) == 0 { @@ -108,7 +112,7 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.Han } var request types.RPCRequest - err := json.Unmarshal(b, &request) + err = json.Unmarshal(b, &request) if err != nil { WriteRPCResponseHTTP(w, types.RPCParseError("", errors.Wrap(err, "Error unmarshalling request"))) return diff --git a/rpc/lib/server/http_server.go b/rpc/lib/server/http_server.go index 4e0f2bd08..515baf5dd 100644 --- a/rpc/lib/server/http_server.go +++ b/rpc/lib/server/http_server.go @@ -56,7 +56,7 @@ func WriteRPCResponseHTTPError(w http.ResponseWriter, httpCode int, res types.RP w.Header().Set("Content-Type", "application/json") w.WriteHeader(httpCode) - w.Write(jsonBytes) // nolint: errcheck + w.Write(jsonBytes) // nolint: errcheck, gas } func WriteRPCResponseHTTP(w http.ResponseWriter, res types.RPCResponse) { @@ -66,7 +66,7 @@ func WriteRPCResponseHTTP(w http.ResponseWriter, res types.RPCResponse) { } w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) - w.Write(jsonBytes) // nolint: errcheck + w.Write(jsonBytes) // nolint: errcheck, gas } //----------------------------------------------------------------------------- diff --git a/scripts/wal2json/main.go b/scripts/wal2json/main.go index 2cf40c57d..e44ed4b17 100644 --- a/scripts/wal2json/main.go +++ b/scripts/wal2json/main.go @@ -41,10 +41,18 @@ func main() { panic(fmt.Errorf("failed to marshal msg: %v", err)) } - os.Stdout.Write(json) - os.Stdout.Write([]byte("\n")) - if end, ok := msg.Msg.(cs.EndHeightMessage); ok { - os.Stdout.Write([]byte(fmt.Sprintf("ENDHEIGHT %d\n", end.Height))) + _, err = os.Stdout.Write(json) + if err == nil { + _, err = os.Stdout.Write([]byte("\n")) + } + if err == nil { + if end, ok := msg.Msg.(cs.EndHeightMessage); ok { + _, err = os.Stdout.Write([]byte(fmt.Sprintf("ENDHEIGHT %d\n", end.Height))) // nolint: errcheck, gas + } + } + if err != nil { + fmt.Println("Failed to write message", err) + os.Exit(1) } } } diff --git a/types/part_set.go b/types/part_set.go index d553572f3..e8a0997c0 100644 --- a/types/part_set.go +++ b/types/part_set.go @@ -34,7 +34,7 @@ func (part *Part) Hash() []byte { return part.hash } else { hasher := ripemd160.New() - hasher.Write(part.Bytes) // nolint: errcheck + hasher.Write(part.Bytes) // nolint: errcheck, gas part.hash = hasher.Sum(nil) return part.hash }