From 44a3859dc95e39df6a4bedc66e688f6b5090c5fa Mon Sep 17 00:00:00 2001 From: Qasim Ayyaz Khan Date: Wed, 13 Jun 2018 08:00:11 +0000 Subject: [PATCH] Patch for Malformed PDU with cmdLength 0. Issue #25. --- lib/session.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/session.js b/lib/session.js index b1fd6fe..0f21d22 100644 --- a/lib/session.js +++ b/lib/session.js @@ -641,6 +641,16 @@ function session(sock) { while (returnObj.dataQueue.length > 4) { const cmdLength = parseInt(returnObj.dataQueue.readUInt32BE(0)); // Get this commands length + // Malformed PDU with command length 0 + if (cmdLength <= 0) { + // Since PDU is Malformed we need to discard buffer. + log.silly(thisLogPrefix + 'Malformed PDU with 0 Length. Discarding buffer.'); + returnObj.dataQueue = returnObj.dataQueue.slice(0, returnObj.dataQueue.length); + + // Since PDU is malformed we need to close socket since we cannot trust data from now on. + returnObj.closeSocket(); + } + let pdu; log.silly(thisLogPrefix + 'Processing ' + cmdLength + ' bytes of data');