Skip to content

Commit bd60295

Browse files
authored
console: fix some crashes/errors in the bridge (#21050)
Fixes #21046
1 parent 930e82d commit bd60295

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎console/bridge.go‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ func (b *bridge) readPinAndReopenWallet(call jsre.Call) (goja.Value, error) {
229229
// original RPC method (saved in jeth.unlockAccount) with it to actually execute
230230
// the RPC call.
231231
func (b *bridge) UnlockAccount(call jsre.Call) (goja.Value, error) {
232+
if nArgs := len(call.Arguments); nArgs < 2 {
233+
return nil, fmt.Errorf("usage: unlockAccount(account, [ password, duration ])")
234+
}
232235
// Make sure we have an account specified to unlock.
233236
if call.Argument(0).ExportType().Kind() != reflect.String {
234237
return nil, fmt.Errorf("first argument must be the account to unlock")
@@ -272,6 +275,9 @@ func (b *bridge) UnlockAccount(call jsre.Call) (goja.Value, error) {
272275
// prompt to acquire the passphrase and executes the original RPC method (saved in
273276
// jeth.sign) with it to actually execute the RPC call.
274277
func (b *bridge) Sign(call jsre.Call) (goja.Value, error) {
278+
if nArgs := len(call.Arguments); nArgs < 2 {
279+
return nil, fmt.Errorf("usage: sign(message, account, [ password ])")
280+
}
275281
var (
276282
message = call.Argument(0)
277283
account = call.Argument(1)
@@ -307,6 +313,9 @@ func (b *bridge) Sign(call jsre.Call) (goja.Value, error) {
307313

308314
// Sleep will block the console for the specified number of seconds.
309315
func (b *bridge) Sleep(call jsre.Call) (goja.Value, error) {
316+
if nArgs := len(call.Arguments); nArgs < 1 {
317+
return nil, fmt.Errorf("usage: sleep(<number of seconds>)")
318+
}
310319
if !isNumber(call.Argument(0)) {
311320
return nil, fmt.Errorf("usage: sleep(<number of seconds>)")
312321
}
@@ -334,7 +343,7 @@ func (b *bridge) SleepBlocks(call jsre.Call) (goja.Value, error) {
334343
blocks = call.Argument(0).ToInteger()
335344
}
336345
if nArgs >= 2 {
337-
if isNumber(call.Argument(1)) {
346+
if !isNumber(call.Argument(1)) {
338347
return nil, fmt.Errorf("expected number as second argument")
339348
}
340349
sleep = call.Argument(1).ToInteger()

0 commit comments

Comments
 (0)