diff options
author | Felix Lange <fjl@twurst.com> | 2015-03-21 05:33:40 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-03-21 05:33:40 +0800 |
commit | b41185a68f2ec8c492a7dbec1a6bf65f29b0843a (patch) | |
tree | 309fe50a122cd1db099381e8961349d842fac765 /rlp/decode.go | |
parent | 28ddc16a9b5779b6b31036e8248ed8457de7b443 (diff) | |
download | dexon-b41185a68f2ec8c492a7dbec1a6bf65f29b0843a.tar.gz dexon-b41185a68f2ec8c492a7dbec1a6bf65f29b0843a.tar.zst dexon-b41185a68f2ec8c492a7dbec1a6bf65f29b0843a.zip |
rlp: fix nil pointer decoding
The generic pointer decoder did not advance the input position
for empty values. This can lead to strange issues and even
infinite loops.
Diffstat (limited to 'rlp/decode.go')
-rw-r--r-- | rlp/decode.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/rlp/decode.go b/rlp/decode.go index 6d7e670c2..0e99d9caa 100644 --- a/rlp/decode.go +++ b/rlp/decode.go @@ -367,7 +367,12 @@ func makePtrDecoder(typ reflect.Type) (decoder, error) { dec := func(s *Stream, val reflect.Value) (err error) { _, size, err := s.Kind() if err != nil || size == 0 && s.byteval == 0 { - val.Set(reflect.Zero(typ)) // set to nil + // rearm s.Kind. This is important because the input + // position must advance to the next value even though + // we don't read anything. + s.kind = -1 + // set the pointer to nil. + val.Set(reflect.Zero(typ)) return err } newval := val |