From f21906a9b031d78295a5f72394b352fa2c491bca Mon Sep 17 00:00:00 2001 From: Tevic Date: Tue, 31 Aug 2021 21:05:04 +0800 Subject: [PATCH] fix: check obj type in protobufBinding --- binding/protobuf.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/binding/protobuf.go b/binding/protobuf.go index ca02897a..a4e47153 100644 --- a/binding/protobuf.go +++ b/binding/protobuf.go @@ -5,6 +5,7 @@ package binding import ( + "errors" "io/ioutil" "net/http" @@ -26,7 +27,11 @@ func (b protobufBinding) Bind(req *http.Request, obj interface{}) error { } func (protobufBinding) BindBody(body []byte, obj interface{}) error { - if err := proto.Unmarshal(body, obj.(proto.Message)); err != nil { + msg, ok := obj.(proto.Message) + if !ok { + return errors.New("obj is not ProtoMessage") + } + if err := proto.Unmarshal(body, msg); err != nil { return err } // Here it's same to return validate(obj), but util now we can't add