From 7c7c480eb895cb3d1ad9b02c890bbbb1d0a961eb Mon Sep 17 00:00:00 2001 From: Patrick Mooney Date: Sat, 15 Mar 2014 16:06:42 -0500 Subject: [PATCH] Improve parser error handling In cases where one side of the connection is not communicated with valid ASN.1/BER, it would be better to fire an error event rather than let the exception bubble all the way up. Fix mcavage/node-ldapjs#142 --- lib/messages/parser.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/messages/parser.js b/lib/messages/parser.js index 10a7130..17109c8 100644 --- a/lib/messages/parser.js +++ b/lib/messages/parser.js @@ -113,8 +113,14 @@ Parser.prototype.getMessage = function (ber) { var self = this; - var messageID = ber.readInt(); - var type = ber.readSequence(); + try { + var messageID = ber.readInt(); + var type = ber.readSequence(); + } catch (e) { + // Handle servers that aren't speaking the language at all + this.emit('error', e); + return false; + } var Message; switch (type) {