Skip to content

Commit

Permalink
Cleaning file path before using it
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodeymo committed Sep 25, 2024
1 parent be89661 commit a0dc83e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crypto/bls/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (k *KeyPair) EncryptedString(path string, password string) ([]byte, error)
}

func ReadPrivateKeyFromFile(path string, password string) (*KeyPair, error) {
keyStoreContents, err := os.ReadFile(path)
keyStoreContents, err := os.ReadFile(filepath.Clean(path))
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions crypto/ecdsa/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func writeBytesToFile(path string, data []byte) error {
}

func ReadKey(keyStoreFile string, password string) (*ecdsa.PrivateKey, error) {
keyStoreContents, err := os.ReadFile(keyStoreFile)
keyStoreContents, err := os.ReadFile(filepath.Clean(keyStoreFile))
if err != nil {
return nil, err
}
Expand All @@ -97,7 +97,7 @@ func ReadKey(keyStoreFile string, password string) (*ecdsa.PrivateKey, error) {
// GetAddressFromKeyStoreFile We are using Web3 format defined by
// https://ethereum.org/en/developers/docs/data-structures-and-encoding/web3-secret-storage/
func GetAddressFromKeyStoreFile(keyStoreFile string) (gethcommon.Address, error) {
keyJson, err := os.ReadFile(keyStoreFile)
keyJson, err := os.ReadFile(filepath.Clean(keyStoreFile))
if err != nil {
return gethcommon.Address{}, err
}
Expand Down
3 changes: 2 additions & 1 deletion signer/privatekey_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"math/big"
"os"
"path/filepath"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/keystore"
Expand Down Expand Up @@ -56,7 +57,7 @@ func (p *PrivateKeySigner) SendToExternal(ctx context.Context, tx *types.Transac
}

func getECDSAPrivateKey(keyStoreFile string, password string) (*ecdsa.PrivateKey, error) {
keyStoreContents, err := os.ReadFile(keyStoreFile)
keyStoreContents, err := os.ReadFile(filepath.Clean(keyStoreFile))
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion testutils/test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"log"
"os"
"path/filepath"
)

// Test data for generic loading of JSON data files.
Expand All @@ -15,7 +16,7 @@ type TestData[T any] struct {
func NewTestData[T any](defaultInput T) TestData[T] {
path, exists := os.LookupEnv("TEST_DATA_PATH")
if exists {
file, err := os.ReadFile(path)
file, err := os.ReadFile(filepath.Clean(path))
if err != nil {
log.Fatalf("Failed to open file: %v", err)
}
Expand Down

0 comments on commit a0dc83e

Please sign in to comment.