mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2024-12-29 12:17:48 +00:00
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:
parent
3e80249d38
commit
e87cf53d57
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user