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

goprotobuf: Check GetProperties is passed a struct early on.

This avoids a a dangling lock later on if a bad type is passed in.

LGTM=gmlewis
R=gmlewis
CC=golang-codereviews
https://codereview.appspot.com/152440043
David Symonds 11 лет назад
Родитель
Сommit
905b3fdd57
1 измененных файлов с 4 добавлено и 0 удалено
  1. 4 0
      proto/properties.go

+ 4 - 0
proto/properties.go

@@ -538,7 +538,11 @@ var (
 )
 
 // GetProperties returns the list of properties for the type represented by t.
+// t must represent a generated struct type of a protocol message.
 func GetProperties(t reflect.Type) *StructProperties {
+	if t.Kind() != reflect.Struct {
+		panic("proto: type must have kind struct")
+	}
 	mutex.Lock()
 	sprop := getPropertiesLocked(t)
 	mutex.Unlock()