Legacy ping is only allowed when in HANDSHAKING state (otherwise, varint packet length 254)

This commit is contained in:
deathcap 2016-01-30 15:28:40 -08:00
parent 4840ffe7b1
commit 9b824b5b88
2 changed files with 4 additions and 3 deletions

View File

@ -14,6 +14,7 @@ class Client extends EventEmitter
super();
this.version=version;
this.isServer = !!isServer;
this.splitter=framing.createSplitter();
this.setSerializer(states.HANDSHAKING);
this.packetsToParse={};
this.serializer;
@ -21,7 +22,6 @@ class Client extends EventEmitter
this.framer=framing.createFramer();
this.cipher=null;
this.decipher=null;
this.splitter=framing.createSplitter();
this.decompressor=null;
this.deserializer;
this.isServer;
@ -51,6 +51,7 @@ class Client extends EventEmitter
this.deserializer = createDeserializer({ isServer:this.isServer, version:this.version, state: state, packetsToParse:
this.packetsToParse});
this.splitter.recognizeLegacyPing = state === states.HANDSHAKING;
this.serializer.on('error', (e) => {
var parts=e.field.split(".");

View File

@ -29,12 +29,12 @@ class Splitter extends Transform {
constructor() {
super();
this.buffer = new Buffer(0);
this.recognizeLegacyPing = false;
}
_transform(chunk, enc, cb) {
this.buffer = Buffer.concat([this.buffer, chunk]);
// TODO: only decode if in handshake state! important since 254 is a valid varint (encodes as 0xfe 0x01), packet length
if (this.buffer[0] === LEGACY_PING_PACKET_ID) {
if (this.recognizeLegacyPing && this.buffer[0] === LEGACY_PING_PACKET_ID) {
// legacy_server_list_ping packet follows a different protocol format
// prefix the encoded varint packet id for the deserializer
var header = new Buffer(sizeOfVarInt(LEGACY_PING_PACKET_ID));