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

Cleaning file path before using it #353

Merged
merged 1 commit into from
Oct 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
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