Skip to content

Commit 0d043d0

Browse files
authored
signer/core: prevent nil pointer panics in keystore operations (ethereum#33829)
Add nil checks to prevent potential panics when keystore backend is unavailable in the Clef signer API.
1 parent ecee64e commit 0d043d0

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

signer/core/uiapi.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ type rawWallet struct {
7373
// Example call
7474
// {"jsonrpc":"2.0","method":"clef_listWallets","params":[], "id":5}
7575
func (api *UIServerAPI) ListWallets() []rawWallet {
76-
wallets := make([]rawWallet, 0) // return [] instead of nil if empty
77-
for _, wallet := range api.am.Wallets() {
76+
allWallets := api.am.Wallets()
77+
wallets := make([]rawWallet, 0, len(allWallets)) // return [] instead of nil if empty
78+
for _, wallet := range allWallets {
7879
status, failure := wallet.Status()
7980

8081
raw := rawWallet{
@@ -130,8 +131,12 @@ func (api *UIServerAPI) ImportRawKey(privkey string, password string) (accounts.
130131
if err := ValidatePasswordFormat(password); err != nil {
131132
return accounts.Account{}, fmt.Errorf("password requirements not met: %v", err)
132133
}
134+
ks := fetchKeystore(api.am)
135+
if ks == nil {
136+
return accounts.Account{}, errors.New("password based accounts not supported")
137+
}
133138
// No error
134-
return fetchKeystore(api.am).ImportECDSA(key, password)
139+
return ks.ImportECDSA(key, password)
135140
}
136141

137142
// OpenWallet initiates a hardware wallet opening procedure, establishing a USB

0 commit comments

Comments
 (0)