Skip to content

Commit 7ff4af7

Browse files
committed
Fix incorrect sequence packet errors to be catchable
fixes #867
1 parent 4b66979 commit 7ff4af7

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

Changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ you spot any mistakes.
66

77
## HEAD
88

9+
* Fix incorrect sequence packet errors to be catchable #867
910
* Fix stray protocol packet errors to be catchable #867
1011
* Fix timing of fatal protocol errors bubbling to user #879
1112

lib/protocol/Protocol.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,9 @@ Protocol.prototype._parsePacket = function() {
231231
return;
232232
}
233233

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;
238237

239238
// Special case: Faster dispatch, and parsing done inside sequence
240239
if (Packet === Packets.RowDataPacket) {
@@ -258,7 +257,17 @@ Protocol.prototype._parsePacket = function() {
258257
}
259258

260259
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);
262271
};
263272

264273
Protocol.prototype._parsePacketDebug = function _parsePacketDebug(packet) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
});

0 commit comments

Comments
 (0)