Просмотр исходного кода

Check we get both key and value from a decoded map entry.

Previously the code assumed a well-formed map entry,
and would panic in the SetMapIndex call if the map was
missing either the key or value field.

Fixes #27.
David Symonds 10 лет назад
Родитель
Сommit
efd7476481
1 измененных файлов с 7 добавлено и 1 удалено
  1. 7 1
      proto/decode.go

+ 7 - 1
proto/decode.go

@@ -727,8 +727,14 @@ func (o *Buffer) dec_new_map(p *Properties, base structPointer) error {
 			return fmt.Errorf("proto: bad map data tag %d", raw[0])
 		}
 	}
+	keyelem, valelem := keyptr.Elem(), valptr.Elem()
+	if !keyelem.IsValid() || !valelem.IsValid() {
+		// We did not decode the key or the value in the map entry.
+		// Either way, it's an invalid map entry.
+		return fmt.Errorf("proto: bad map data: missing key/val")
+	}
 
-	v.SetMapIndex(keyptr.Elem(), valptr.Elem())
+	v.SetMapIndex(keyelem, valelem)
 	return nil
 }