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.
This commit is contained in:
Felix Lange
2015-03-20 22:33:40 +01:00
parent 28ddc16a9b
commit b41185a68f
2 changed files with 27 additions and 2 deletions

View File

@ -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