Fix buffer OOB error and re-style traffic debug output

fork
Brian White 12 years ago
parent 4c03c7519c
commit a9062b98f3

@ -161,13 +161,13 @@ ImapConnection.prototype.connect = function(loginCb) {
function read(b) {
var blen = b.length;
if (ondata.expect <= blen) {
if (ondata.expect <= (blen - b.p)) {
var left = ondata.expect, origPos = b.p;
ondata.expect = 0;
b.p += left;
return b.slice(origPos, origPos + left);
} else {
ondata.expect -= blen;
ondata.expect -= (blen - b.p);
b.p = blen;
return b;
}
@ -176,7 +176,7 @@ ImapConnection.prototype.connect = function(loginCb) {
var ondata = function(b) {
b.p || (b.p = 0);
if (b.length === 0 || b.p >= b.length) return;
self.debug&&self.debug('\n<-- ' + inspect(b.toString('binary', b.p)) + '\n');
self.debug&&self.debug('\n<== ' + inspect(b.toString('binary', b.p)) + '\n');
var r, m, litType;
if (ondata.expect > 0) {
@ -761,7 +761,7 @@ ImapConnection.prototype.append = function(data, options, cb) {
return cb(err);
self._state.conn.cleartext.write(data);
self._state.conn.cleartext.write(CRLF);
self.debug&&self.debug('\n--> ' + inspect(data.toString()) + '\n');
self.debug&&self.debug('\n==> ' + inspect(data.toString()) + '\n');
});
};
@ -1168,7 +1168,7 @@ ImapConnection.prototype._send = function(cmdstr, cb, bypass) {
this._state.conn.cleartext.write(prefix);
this._state.conn.cleartext.write(cmd);
this._state.conn.cleartext.write(CRLF);
this.debug&&this.debug('\n--> ' + prefix + cmd + '\n');
this.debug&&this.debug('\n==> ' + prefix + cmd + '\n');
}
};

Loading…
Cancel
Save