File tree 3 files changed +39
-5
lines changed
3 files changed +39
-5
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ you spot any mistakes.
6
6
7
7
## HEAD
8
8
9
+ * Fix incorrect sequence packet errors to be catchable #867
9
10
* Fix stray protocol packet errors to be catchable #867
10
11
* Fix timing of fatal protocol errors bubbling to user #879
11
12
Original file line number Diff line number Diff line change @@ -231,10 +231,9 @@ Protocol.prototype._parsePacket = function() {
231
231
return ;
232
232
}
233
233
234
- var Packet = this . _determinePacket ( sequence ) ;
235
- var packet = new Packet ( {
236
- protocol41 : this . _config . protocol41
237
- } ) ;
234
+ var Packet = this . _determinePacket ( sequence ) ;
235
+ var packet = new Packet ( { protocol41 : this . _config . protocol41 } ) ;
236
+ var packetName = Packet . name ;
238
237
239
238
// Special case: Faster dispatch, and parsing done inside sequence
240
239
if ( Packet === Packets . RowDataPacket ) {
@@ -258,7 +257,17 @@ Protocol.prototype._parsePacket = function() {
258
257
}
259
258
260
259
Timers . active ( sequence ) ;
261
- sequence [ Packet . name ] ( packet ) ;
260
+
261
+ if ( ! sequence [ packetName ] ) {
262
+ var err = new Error ( 'Received packet in the wrong sequence.' ) ;
263
+ err . code = 'PROTOCOL_INCORRECT_PACKET_SEQUENCE' ;
264
+ err . fatal = true ;
265
+
266
+ this . _delegateError ( err ) ;
267
+ return ;
268
+ }
269
+
270
+ sequence [ packetName ] ( packet ) ;
262
271
} ;
263
272
264
273
Protocol . prototype . _parsePacketDebug = function _parsePacketDebug ( packet ) {
Original file line number Diff line number Diff line change
1
+ var assert = require ( 'assert' ) ;
2
+ var common = require ( '../../common' ) ;
3
+ var connection = common . createConnection ( { port : common . fakeServerPort } ) ;
4
+ var server = common . createFakeServer ( ) ;
5
+
6
+ server . listen ( common . fakeServerPort , function ( err ) {
7
+ assert . ifError ( err ) ;
8
+
9
+ connection . ping ( function ( err ) {
10
+ assert . ok ( err , 'got error' ) ;
11
+ assert . equal ( err . code , 'PROTOCOL_INCORRECT_PACKET_SEQUENCE' ) ;
12
+ assert . equal ( err . fatal , true ) ;
13
+ connection . destroy ( ) ;
14
+ server . destroy ( ) ;
15
+ } ) ;
16
+ } ) ;
17
+
18
+ server . on ( 'connection' , function ( connection ) {
19
+ connection . handshake ( ) ;
20
+ connection . on ( 'ping' , function ( ) {
21
+ this . _sendPacket ( new common . Packets . EofPacket ( ) ) ;
22
+ this . _parser . resetPacketNumber ( ) ;
23
+ } ) ;
24
+ } ) ;
You can’t perform that action at this time.
0 commit comments