accounts/abi: fix panic in MethodById lookup. Fixes #17797 (#17798)

This commit is contained in:
Martin Holst Swende
2018-10-01 14:17:37 +02:00
committed by Guillaume Ballet
parent dc5d643bb5
commit 96fd50be10
2 changed files with 13 additions and 1 deletions

View File

@ -137,6 +137,9 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
// MethodById looks up a method by the 4-byte id
// returns nil if none found
func (abi *ABI) MethodById(sigdata []byte) (*Method, error) {
if len(sigdata) < 4 {
return nil, fmt.Errorf("data too short (% bytes) for abi method lookup", len(sigdata))
}
for _, method := range abi.Methods {
if bytes.Equal(method.Id(), sigdata[:4]) {
return &method, nil