Skip to content

Commit 8820d97

Browse files
authored
internal/ethapi: fix duration parameter of personal_unlockAccount (#3542)
1 parent b52fde7 commit 8820d97

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

internal/ethapi/api.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ package ethapi
1919
import (
2020
"bytes"
2121
"encoding/hex"
22+
"errors"
2223
"fmt"
24+
"math"
2325
"math/big"
2426
"strings"
2527
"time"
@@ -237,17 +239,18 @@ func (s *PrivateAccountAPI) ImportRawKey(privkey string, password string) (commo
237239
// UnlockAccount will unlock the account associated with the given address with
238240
// the given password for duration seconds. If duration is nil it will use a
239241
// default of 300 seconds. It returns an indication if the account was unlocked.
240-
func (s *PrivateAccountAPI) UnlockAccount(addr common.Address, password string, duration *hexutil.Uint) (bool, error) {
242+
func (s *PrivateAccountAPI) UnlockAccount(addr common.Address, password string, duration *uint64) (bool, error) {
243+
const max = uint64(time.Duration(math.MaxInt64) / time.Second)
241244
var d time.Duration
242245
if duration == nil {
243246
d = 300 * time.Second
247+
} else if *duration > max {
248+
return false, errors.New("unlock duration too large")
244249
} else {
245250
d = time.Duration(*duration) * time.Second
246251
}
247-
if err := s.am.TimedUnlock(accounts.Account{Address: addr}, password, d); err != nil {
248-
return false, err
249-
}
250-
return true, nil
252+
err := s.am.TimedUnlock(accounts.Account{Address: addr}, password, d)
253+
return err == nil, err
251254
}
252255

253256
// LockAccount will lock the account associated with the given address when it's unlocked.

0 commit comments

Comments
 (0)