internal/impl: fix panic calling XXX_MessageName on aberrant messages

Call XXX_MessageName with best-effort. If it panics, oh-well.

Change-Id: I605ea074470b0c90b0bea8b36fa7d4a69368692d
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/194598
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
Joe Tsai 2019-09-10 12:20:00 -07:00
parent 3e80249d38
commit e87cf53d57

View File

@ -202,10 +202,14 @@ func aberrantDeriveMessageName(t reflect.Type, name pref.FullName) pref.FullName
if name.IsValid() {
return name
}
if m, ok := reflect.New(t).Interface().(interface{ XXX_MessageName() string }); ok {
if name := pref.FullName(m.XXX_MessageName()); name.IsValid() {
return name
func() {
defer func() { recover() }() // swallow possible nil panics
if m, ok := reflect.New(t).Interface().(interface{ XXX_MessageName() string }); ok {
name = pref.FullName(m.XXX_MessageName())
}
}()
if name.IsValid() {
return name
}
return aberrantDeriveFullName(t)
}