Skip to content

Commit

Permalink
Don't try to parse unknown session track blocks. Fixes #989
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Sidorov committed Aug 19, 2019
1 parent 46744ca commit 6dd8a4d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/packets/resultset_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ResultSetHeader {
const encoding = connection.serverEncoding;
const flags = connection._handshakePacket.capabilityFlags;
const isSet = function(flag) {
console.log('isSet?', flag, ClientConstants[flag]);
return flags & ClientConstants[flag];
};
if (packet.buffer[packet.offset] !== 0) {
Expand All @@ -36,7 +37,9 @@ class ResultSetHeader {
}
let stateChanges = null;
if (isSet('SESSION_TRACK') && packet.offset < packet.end) {
const sessionInfoTypes = require('../constants/session_track.js');
this.info = packet.readLengthCodedString(encoding);

if (this.serverStatus && ServerSatusFlags.SERVER_SESSION_STATE_CHANGED) {
// session change info record - see
// https://dev.mysql.com/doc/internals/en/packet-OK_Packet.html#cs-sect-packet-ok-sessioninfo
Expand All @@ -48,31 +51,30 @@ class ResultSetHeader {
stateChanges = {
systemVariables: {},
schema: null,
// gtids: {},
trackStateChange: null
};
}
while (packet.offset < end) {
type = packet.readInt8();
len = packet.readLengthCodedNumber();
stateEnd = packet.offset + len;
key = packet.readLengthCodedString(encoding);
if (type === 0) {
if (type === sessionInfoTypes.SYSTEM_VARIABLES) {
key = packet.readLengthCodedString(encoding);
const val = packet.readLengthCodedString(encoding);
stateChanges.systemVariables[key] = val;
if (key === 'character_set_client') {
const charsetNumber = EncodingToCharset[val];
connection.config.charsetNumber = charsetNumber;
}
} else if (type === 1) {
// TODO double check it's supposed to be the only value, not a list.
} else if (type === sessionInfoTypes.SCHEMA) {
key = packet.readLengthCodedString(encoding);
stateChanges.schema = key;
} else if (type === 2) {
} else if (type === sessionInfoTypes.STATE_CHANGE) {
stateChanges.trackStateChange = packet.readLengthCodedString(
encoding
);
} else {
// GTIDs (type == 3) or unknown type - just skip for now
// unsupported session track type. For now just ignore
}
packet.offset = stateEnd;
}
Expand Down

0 comments on commit 6dd8a4d

Please sign in to comment.