From 3c5eb201f4f7786c125d5b10f6dcccd50bd97cfc Mon Sep 17 00:00:00 2001 From: Stephen Palmer Date: Fri, 13 Apr 2018 08:56:14 -0500 Subject: [PATCH 1/4] =?UTF-8?q?-=20Fixed=20bug=20where=20a=20=E2=80=98q?= =?UTF-8?q?=E2=80=99=20character=20is=20mis-interpreted=20as=20a=20quit=20?= =?UTF-8?q?command,=20if=20that=20character=20was=20received=20as=20a=20si?= =?UTF-8?q?ngle=20packet=20in=20the=20middle=20of=20reading=20data=20for?= =?UTF-8?q?=20another=20command.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/server/client_stream_processor.js | 2 +- test/protocol.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/server/client_stream_processor.js b/lib/server/client_stream_processor.js index 5849f1f..2ea4a40 100644 --- a/lib/server/client_stream_processor.js +++ b/lib/server/client_stream_processor.js @@ -122,7 +122,7 @@ class ClientStreamProcessor extends Transform { if(!fillBufferWithData()) { // Quit? - if (data[data.length - 1] === CMD_QUIT) { + if (!readState.didParseCmd && data[data.length - 1] === CMD_QUIT) { this.push('q'); } diff --git a/test/protocol.js b/test/protocol.js index d706f9e..782e481 100644 --- a/test/protocol.js +++ b/test/protocol.js @@ -153,6 +153,11 @@ describe("Protocol", () => { tests.forEach(function (test) { it(`should store ${test.ext} data with a (${test.cmd}) command (client write packet size = ${test.packetSize})`, () => { + // Insert 'q' character ('Quit' command) into the GUID, to catch subtle protocol errors when packet size is 1 + if(test.packetSize === 1) { + test.data.guid[test.data.guid.length - 1] = 113; + } + const buf = Buffer.from( encodeCommand(cmd.transactionStart, test.data.guid, test.data.hash) + encodeCommand(test.cmd, null, null, test.data[test.ext]) + From 59d07c521e029c0f32595bd2b63f28acb27a3616 Mon Sep 17 00:00:00 2001 From: Stephen Palmer Date: Fri, 13 Apr 2018 10:04:10 -0500 Subject: [PATCH 2/4] clarify code by using charCodeAt instead of the value --- test/protocol.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/protocol.js b/test/protocol.js index 782e481..bf783a4 100644 --- a/test/protocol.js +++ b/test/protocol.js @@ -155,7 +155,7 @@ describe("Protocol", () => { it(`should store ${test.ext} data with a (${test.cmd}) command (client write packet size = ${test.packetSize})`, () => { // Insert 'q' character ('Quit' command) into the GUID, to catch subtle protocol errors when packet size is 1 if(test.packetSize === 1) { - test.data.guid[test.data.guid.length - 1] = 113; + test.data.guid[test.data.guid.length - 1] = 'q'.charCodeAt(0); } const buf = Buffer.from( From 49cde122a6abf4fa79d5b32234b1748a0acfd367 Mon Sep 17 00:00:00 2001 From: Stephen Palmer Date: Fri, 13 Apr 2018 11:12:12 -0500 Subject: [PATCH 3/4] =?UTF-8?q?Add=20an=20additional=20=E2=80=98q=E2=80=99?= =?UTF-8?q?=20char=20to=20the=20beginning=20of=20GUID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/protocol.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/protocol.js b/test/protocol.js index bf783a4..64d6e0a 100644 --- a/test/protocol.js +++ b/test/protocol.js @@ -156,6 +156,7 @@ describe("Protocol", () => { // Insert 'q' character ('Quit' command) into the GUID, to catch subtle protocol errors when packet size is 1 if(test.packetSize === 1) { test.data.guid[test.data.guid.length - 1] = 'q'.charCodeAt(0); + test.data.guid[0] = 'q'.charCodeAt(0); } const buf = Buffer.from( From f107896ea44793d2b224e3bfec0d54bfe5a9678c Mon Sep 17 00:00:00 2001 From: Stephen Palmer Date: Fri, 13 Apr 2018 11:17:46 -0500 Subject: [PATCH 4/4] simplifying an expression --- test/protocol.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/protocol.js b/test/protocol.js index 64d6e0a..db15309 100644 --- a/test/protocol.js +++ b/test/protocol.js @@ -155,8 +155,7 @@ describe("Protocol", () => { it(`should store ${test.ext} data with a (${test.cmd}) command (client write packet size = ${test.packetSize})`, () => { // Insert 'q' character ('Quit' command) into the GUID, to catch subtle protocol errors when packet size is 1 if(test.packetSize === 1) { - test.data.guid[test.data.guid.length - 1] = 'q'.charCodeAt(0); - test.data.guid[0] = 'q'.charCodeAt(0); + test.data.guid[0] = test.data.guid[test.data.guid.length - 1] = 'q'.charCodeAt(0); } const buf = Buffer.from(