fix: gosec issues (#779)

* remove gosec warnigs with medium severity

* Improvement(Ethermint): Fix gosec vulnerabilities

* Improvement(Evmos): address pr comments

* Improvement(Ethermint): Fix flags test by using PersistentFlags() instead of Flags()

* Improvement(Ethermint): Fix return of defer function

* Improvement(Ethermint): Replace PersistentFlags with Flags

* Apply suggestions from code review

* Improvement(Ethermint): Use persisentFlags again and remove required attribute for chain id

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
Daniel Burckhardt
2021-11-25 15:12:57 +00:00
committed by GitHub
co-authored by Federico Kunze Küllmer
parent 32eaec8d99
commit 2d8be4e85b
9 changed files with 63 additions and 29 deletions
+10 -2
View File
@@ -19,8 +19,10 @@ import (
evmtypes "github.com/tharsis/ethermint/x/evm/types"
"github.com/cosmos/cosmos-sdk/client"
stderrors "github.com/pkg/errors"
"github.com/cosmos/cosmos-sdk/server"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus/ethash"
@@ -351,7 +353,10 @@ func (a *API) StartCPUProfile(file string) error {
}
if err := pprof.StartCPUProfile(f); err != nil {
a.logger.Debug("cpu profiling already in use", "error", err.Error())
f.Close()
if err := f.Close(); err != nil {
a.logger.Debug("failed to close cpu profile file")
return stderrors.Wrap(err, "failed to close cpu profile file")
}
return err
}
@@ -375,7 +380,10 @@ func (a *API) StopCPUProfile() error {
case a.handler.cpuFile != nil:
a.logger.Info("Done writing CPU profile", "profile", a.handler.cpuFilename)
pprof.StopCPUProfile()
a.handler.cpuFile.Close()
if err := a.handler.cpuFile.Close(); err != nil {
a.logger.Debug("failed to close cpu file")
return stderrors.Wrap(err, "failed to close cpu file")
}
a.handler.cpuFile = nil
a.handler.cpuFilename = ""
return nil
+11 -2
View File
@@ -23,6 +23,8 @@ import (
"errors"
"os"
"runtime/trace"
stderrors "github.com/pkg/errors"
)
// StartGoTrace turns on tracing, writing to the given file.
@@ -47,7 +49,11 @@ func (a *API) StartGoTrace(file string) error {
}
if err := trace.Start(f); err != nil {
a.logger.Debug("Go tracing already started", "error", err.Error())
f.Close()
if err := f.Close(); err != nil {
a.logger.Debug("failed to close trace file")
return stderrors.Wrap(err, "failed to close trace file")
}
return err
}
a.handler.traceFile = f
@@ -68,7 +74,10 @@ func (a *API) StopGoTrace() error {
return errors.New("trace not in progress")
}
a.logger.Info("Done writing Go trace", "dump", a.handler.traceFilename)
a.handler.traceFile.Close()
if err := a.handler.traceFile.Close(); err != nil {
a.logger.Debug("failed to close trace file")
return stderrors.Wrap(err, "failed to close trace file")
}
a.handler.traceFile = nil
a.handler.traceFilename = ""
return nil
+3 -1
View File
@@ -50,7 +50,9 @@ func writeProfile(name, file string, log log.Logger) error {
}
if err := p.WriteTo(f, 0); err != nil {
f.Close()
if err := f.Close(); err != nil {
return err
}
return err
}