Skip to content

Commit aa523b8

Browse files
committed
fix possible connection crashes as per PR mscdex#564
see PR mscdex#564 in original repo: mscdex#546 These crashes might result from user errors... but still it makes sense to not just crash because of accessing uninitialized variables.
1 parent 58b477a commit aa523b8

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lib/Connection.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,16 @@ class Connection extends EventEmitter {
190190
self._resTagged(info)
191191
})
192192
parser.on('body', function (stream, info) {
193-
let msg = self._curReq.fetchCache[info.seqno]
194-
let toget
193+
if (!self._curReq) {
194+
stream.resume();
195+
return;
196+
}
197+
let msg = undefined;
198+
let toget;
199+
if (self._curReq.fetchCache.hasOwnProperty(info.seqno)) {
200+
msg = self._curReq.fetchCache[info.seqno];
201+
}
202+
195203
if (msg === undefined) {
196204
msg = self._curReq.fetchCache[info.seqno] = {
197205
msgEmitter: new EventEmitter(),
@@ -402,11 +410,13 @@ class Connection extends EventEmitter {
402410
self._box = undefined
403411
cb(err)
404412
}
405-
else {
413+
else if (self._box) {
406414
self._box.name = name
407415
cb(err, self._box)
416+
} else {
417+
cb(new Error('No mailbox is currently selected'));
408418
}
409-
})
419+
});
410420
}
411421
closeBox(shouldExpunge, cb) {
412422
if (this._box === undefined)
@@ -1183,7 +1193,7 @@ class Connection extends EventEmitter {
11831193
this._curReq.cbargs.push(box)
11841194
}
11851195
else if (type === 'fetch') {
1186-
if (/^(?:UID )?FETCH/.test(this._curReq.fullcmd)) {
1196+
if (this._curReq && /^(?:UID )?FETCH/.test(this._curReq.fullcmd)) {
11871197
// FETCH response sent as result of FETCH request
11881198
const msg = this._curReq.fetchCache[info.num], keys = Object.keys(info.text), keyslen = keys.length
11891199
let toget, msgEmitter, j

0 commit comments

Comments
 (0)