File tree Expand file tree Collapse file tree 3 files changed +17
-30
lines changed
Expand file tree Collapse file tree 3 files changed +17
-30
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ require (
2222 go.uber.org/zap v1.13.0
2323 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
2424 golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd
25- golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc // indirect
25+ golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc
2626 google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013
2727 google.golang.org/grpc v1.34.0
2828 google.golang.org/protobuf v1.25.0
Original file line number Diff line number Diff line change @@ -178,21 +178,6 @@ func (r *Reader) ReadPacket() (Packet, error) {
178178 }
179179 fh := & FixHeader {PacketType : first >> 4 , Flags : first & 15 } //设置FixHeader
180180 length , err := EncodeRemainLength (r .bufr )
181-
182- var headerLen int
183- if length <= 127 {
184- headerLen = 2
185- } else if length <= 16383 {
186- headerLen = 3
187- } else if length <= 2097151 {
188- headerLen = 4
189- } else if length <= 268435455 {
190- headerLen = 5
191- }
192- if headerLen + length > 1234 {
193- return nil , codes .NewError (codes .RecvMaxExceeded )
194- }
195-
196181 if err != nil {
197182 return nil , err
198183 }
@@ -296,6 +281,9 @@ func EncodeRemainLength(r io.ByteReader) (int, error) {
296281 return 0 , err
297282 }
298283 vbi |= uint32 (digit & 127 ) << multiplier
284+ if vbi > 268435455 {
285+ return 0 , codes .ErrMalformed
286+ }
299287 if (digit & 128 ) == 0 {
300288 break
301289 }
Original file line number Diff line number Diff line change @@ -302,6 +302,7 @@ func TestFederation_OnUnsubscribedWrapper(t *testing.T) {
302302func TestFederation_OnSessionTerminatedWrapper (t * testing.T ) {
303303 ctrl := gomock .NewController (t )
304304 defer ctrl .Finish ()
305+ a := assert .New (t )
305306 p , _ := New (testConfig )
306307 f := p .(* Federation )
307308 f .localSubStore .init (mem .NewStore ())
@@ -338,19 +339,17 @@ func TestFederation_OnSessionTerminatedWrapper(t *testing.T) {
338339 })
339340 onSessionTerminated (context .Background (), "client2" , 0 )
340341
341- mockQueue .EXPECT ().add (& Event {
342- Event : & Event_Unsubscribe {
343- Unsubscribe : & Unsubscribe {
344- TopicName : "/topicB" ,
345- },
346- },
347- })
348- mockQueue .EXPECT ().add (& Event {
349- Event : & Event_Unsubscribe {
350- Unsubscribe : & Unsubscribe {
351- TopicName : "/topicC" ,
352- },
353- },
354- })
342+ var b , c bool
343+ mockQueue .EXPECT ().add (gomock .Any ()).Do (func (event * Event ) {
344+ if event .Event .(* Event_Unsubscribe ).Unsubscribe .TopicName == "/topicB" {
345+ b = true
346+ }
347+ if event .Event .(* Event_Unsubscribe ).Unsubscribe .TopicName == "/topicC" {
348+ c = true
349+ }
350+ }).Times (2 )
351+
355352 onSessionTerminated (context .Background (), "client3" , 0 )
353+ a .True (b )
354+ a .True (c )
356355}
You can’t perform that action at this time.
0 commit comments