diff --git a/lib/parser/javascript.js b/lib/parser/javascript.js index b2d6cb2387..dd70cf0987 100644 --- a/lib/parser/javascript.js +++ b/lib/parser/javascript.js @@ -46,6 +46,11 @@ ReplyParser.prototype._parseResult = function (type) { // include the delimiter this._offset = end + 2; + if (end > this._buffer.length) { + this._offset = start; + throw new Error("too far"); + } + if (this.options.return_buffers) { return this._buffer.slice(start, end); } else { @@ -63,6 +68,11 @@ ReplyParser.prototype._parseResult = function (type) { // include the delimiter this._offset = end + 2; + if (end > this._buffer.length) { + this._offset = start; + throw new Error("too far"); + } + // return the coerced numeric value return +small_toString(this._buffer, start, end); } else if (type === 36) { // $ @@ -85,7 +95,7 @@ ReplyParser.prototype._parseResult = function (type) { if (end > this._buffer.length) { this._offset = offset; - return null; + throw new Error("too far"); } if (this.options.return_buffers) {