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

Merge fix gosec issues to dev #21

Merged
merged 3 commits into from
Sep 2, 2024
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
8 changes: 5 additions & 3 deletions cmd/sid/cli/btc_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ import (

babylontypes "github.com/babylonlabs-io/babylon/types"
bbnbtclightclienttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"
"github.com/urfave/cli"
"go.uber.org/zap"

"github.com/babylonlabs-io/staking-indexer/btcclient"
"github.com/babylonlabs-io/staking-indexer/btcscanner"
"github.com/babylonlabs-io/staking-indexer/config"
"github.com/babylonlabs-io/staking-indexer/log"
"github.com/babylonlabs-io/staking-indexer/utils"
"github.com/urfave/cli"
"go.uber.org/zap"
)

const (
outputFileFlag = "output"
withHeightFlag = "with-height"
defaultOutputFileName = "btc-headers.json"
filePermission = 0600
)

type HeadersState struct {
Expand Down Expand Up @@ -112,7 +114,7 @@ func btcHeaders(ctx *cli.Context) error {
}

outputFilePath := ctx.String(outputFileFlag)
if err := os.WriteFile(outputFilePath, bz, 0644); err != nil {
if err := os.WriteFile(outputFilePath, bz, filePermission); err != nil {
return fmt.Errorf("failed to write to output file %s: %w", outputFilePath, err)
}

Expand Down
2 changes: 1 addition & 1 deletion itest/test_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func StartManagerWithNBlocks(t *testing.T, n int, startHeight uint64) *TestManag
require.NoError(t, err)

dirPath := filepath.Join(t.TempDir(), "sid", "e2etest")
err = os.MkdirAll(dirPath, 0755)
err = os.MkdirAll(dirPath, 0750)
require.NoError(t, err)

return StartWithBitcoinHandler(t, h, minerAddressDecoded, dirPath, startHeight)
Expand Down
4 changes: 3 additions & 1 deletion log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/babylonlabs-io/staking-indexer/utils"
)

const logFilePermission = 0600

func NewRootLogger(format string, level string, w io.Writer) (*zap.Logger, error) {
cfg := zap.NewProductionEncoderConfig()
cfg.EncodeTime = func(ts time.Time, encoder zapcore.PrimitiveArrayEncoder) {
Expand Down Expand Up @@ -63,7 +65,7 @@ func NewRootLoggerWithFile(logFile string, level string) (*zap.Logger, error) {
if err := utils.MakeDirectory(filepath.Dir(logFile)); err != nil {
return nil, err
}
f, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660)
f, err := os.OpenFile(filepath.Clean(logFile), os.O_CREATE|os.O_WRONLY|os.O_APPEND, logFilePermission)
if err != nil {
return nil, err
}
Expand Down
5 changes: 4 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ func (s *Server) RunUntilShutdown(startHeight uint64) error {

defer func() {
s.logger.Info("Closing database...")
s.db.Close()
err := s.db.Close()
if err != nil {
s.logger.Fatal("error closing the database")
}
s.logger.Info("Database closed")
}()

Expand Down
3 changes: 2 additions & 1 deletion testutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ func MakeTestBackend(t *testing.T) kvdb.Backend {
require.NoError(t, err)

t.Cleanup(func() {
backend.Close()
err := backend.Close()
require.NoError(t, err)
})

return backend
Expand Down
Loading