mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Check file size before reading it into memory
This commit is contained in:
parent
745f0fd521
commit
ae3c77b82b
1 changed files with 9 additions and 3 deletions
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/math"
|
"github.com/ethereum/go-ethereum/common/math"
|
||||||
|
|
@ -164,12 +165,17 @@ func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error) {
|
||||||
|
|
||||||
// LoadECDSA loads a secp256k1 private key from the given file.
|
// LoadECDSA loads a secp256k1 private key from the given file.
|
||||||
func LoadECDSA(file string) (*ecdsa.PrivateKey, error) {
|
func LoadECDSA(file string) (*ecdsa.PrivateKey, error) {
|
||||||
buf, err := ioutil.ReadFile(file)
|
stat, err := os.Stat(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(buf) != 64 {
|
size := stat.Size()
|
||||||
return nil, fmt.Errorf("expected 64 hexa characters, got %v", len(buf))
|
if size != 64 {
|
||||||
|
return nil, fmt.Errorf("expected 64 hexa characters, got %v", size)
|
||||||
|
}
|
||||||
|
buf, err := ioutil.ReadFile(file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := hex.DecodeString(string(buf))
|
key, err := hex.DecodeString(string(buf))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue