From 353f156d1ae41455530165cd2ce11622aa1a52fc Mon Sep 17 00:00:00 2001 From: Xabier de Zuazo Date: Sat, 6 Apr 2013 19:34:10 +0200 Subject: [PATCH 1/7] fix buffer length checking bug in readSlot() --- lib/protocol.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/protocol.js b/lib/protocol.js index 21be784..bdd533e 100644 --- a/lib/protocol.js +++ b/lib/protocol.js @@ -1088,6 +1088,7 @@ function readSlot(buffer, offset) { var nbtDataSize = buffer.readInt16BE(cursor + 3); if (nbtDataSize === -1) nbtDataSize = 0; var nbtDataEnd = cursorEnd + nbtDataSize; + if (nbtDataEnd > buffer.length) return null; var nbtData = buffer.slice(cursorEnd, nbtDataEnd); return { From 086d47b7250db129ae0e6407a0a0c0a4a78e2ec7 Mon Sep 17 00:00:00 2001 From: Xabier de Zuazo Date: Sat, 6 Apr 2013 19:48:22 +0200 Subject: [PATCH 2/7] errors printing in readEntityMetadata() improved --- lib/protocol.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/protocol.js b/lib/protocol.js index bdd533e..9a67b8c 100644 --- a/lib/protocol.js +++ b/lib/protocol.js @@ -776,16 +776,21 @@ function readEntityMetadata(buffer, offset) { key = item & 0x1f; type = item >> 5; typeName = entityMetadataTypes[type]; + if (!typeName) { + return { + error: new Error("unrecognized entity metadata type " + type) + } + } dataType = types[typeName]; if (!dataType) { return { - error: new Error("unrecognized entity metadata type " + type) + error: new Error("unrecognized entity metadata type name " + typeName) } } reader = dataType[0]; if (!reader) { return { - error: new Error("missing reader for entity metadata type " + type) + error: new Error("missing reader for entity metadata type name " + typeName) } } results = reader(buffer, cursor); From 34e06bdd488625de9b0fa3ce7e83e70eac5d3307 Mon Sep 17 00:00:00 2001 From: Xabier de Zuazo Date: Sat, 6 Apr 2013 21:48:39 +0200 Subject: [PATCH 3/7] added entity metadata debugging message --- lib/protocol.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/protocol.js b/lib/protocol.js index 9a67b8c..0958be1 100644 --- a/lib/protocol.js +++ b/lib/protocol.js @@ -776,6 +776,7 @@ function readEntityMetadata(buffer, offset) { key = item & 0x1f; type = item >> 5; typeName = entityMetadataTypes[type]; + debug("Reading entity metadata type " + type + " (" + ( typeName || "unknown" ) + ")"); if (!typeName) { return { error: new Error("unrecognized entity metadata type " + type) From a9afd32ad37a2cebc7fad46be2ee12576552f005 Mon Sep 17 00:00:00 2001 From: Xabier de Zuazo Date: Sun, 7 Apr 2013 11:55:20 +0200 Subject: [PATCH 4/7] fixed C2 calculation bug (fixes #35) --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 296f4d7..e1e7c32 100644 --- a/index.js +++ b/index.js @@ -363,7 +363,7 @@ function mcHexDigest(hash) { newByte = ~value & 0xff; if (carry) { carry = newByte === 0xff; - buffer.writeUInt8(newByte + 1, i); + buffer.writeUInt8((newByte + 1) & 0xff, i); } else { buffer.writeUInt8(newByte, i); } From bcef115c07b954fade8cc33e4784cd4525c82dc7 Mon Sep 17 00:00:00 2001 From: Xabier de Zuazo Date: Sun, 7 Apr 2013 12:02:31 +0200 Subject: [PATCH 5/7] debug message printing when you are trying to connect to an online server without credentials --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index e1e7c32..1420f4c 100644 --- a/index.js +++ b/index.js @@ -267,6 +267,9 @@ function createClient(options) { if (haveCredentials) { joinServerRequest(onJoinServerResponse); } else { + if (packet.serverId != '-') { + debug('This server appears to be an online server and you are providing no password, the authentication will probably fail'); + } sendEncryptionKeyResponse(); } From ab0237e5e6a150bebfb2d83baf81ce0d2fa65d8a Mon Sep 17 00:00:00 2001 From: Xabier de Zuazo Date: Sun, 7 Apr 2013 12:04:29 +0200 Subject: [PATCH 6/7] "hash" varible moved inside joinServerRequest function --- index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 1420f4c..248794d 100644 --- a/index.js +++ b/index.js @@ -261,9 +261,6 @@ function createClient(options) { return } - var hash = crypto.createHash('sha1'); - hash.update(packet.serverId); - if (haveCredentials) { joinServerRequest(onJoinServerResponse); } else { @@ -283,6 +280,8 @@ function createClient(options) { } function joinServerRequest(cb) { + var hash = crypto.createHash('sha1'); + hash.update(packet.serverId); hash.update(sharedSecret); hash.update(packet.publicKey); From cf6fae53025ef4e6dc44b7d7f81efebf67bd1bf1 Mon Sep 17 00:00:00 2001 From: Xabier de Zuazo Date: Sun, 7 Apr 2013 20:47:12 +0200 Subject: [PATCH 7/7] bugfix: debug undefined in inde.js --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 248794d..5f67fdb 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ var EventEmitter = require('events').EventEmitter , protocol = require('./lib/protocol') , Client = require('./lib/client') , Server = require('./lib/server') + , debug = protocol.debug module.exports = { createClient: createClient,