Skip to content

Commit

Permalink
fix possible connection crashes as per PR mscdex#564
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Garfonso committed Mar 23, 2023
1 parent 58b477a commit aa523b8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,16 @@ class Connection extends EventEmitter {
self._resTagged(info)
})
parser.on('body', function (stream, info) {
let msg = self._curReq.fetchCache[info.seqno]
let toget
if (!self._curReq) {
stream.resume();
return;
}
let msg = undefined;
let toget;
if (self._curReq.fetchCache.hasOwnProperty(info.seqno)) {
msg = self._curReq.fetchCache[info.seqno];
}

if (msg === undefined) {
msg = self._curReq.fetchCache[info.seqno] = {
msgEmitter: new EventEmitter(),
Expand Down Expand Up @@ -402,11 +410,13 @@ class Connection extends EventEmitter {
self._box = undefined
cb(err)
}
else {
else if (self._box) {
self._box.name = name
cb(err, self._box)
} else {
cb(new Error('No mailbox is currently selected'));
}
})
});
}
closeBox(shouldExpunge, cb) {
if (this._box === undefined)
Expand Down Expand Up @@ -1183,7 +1193,7 @@ class Connection extends EventEmitter {
this._curReq.cbargs.push(box)
}
else if (type === 'fetch') {
if (/^(?:UID )?FETCH/.test(this._curReq.fullcmd)) {
if (this._curReq && /^(?:UID )?FETCH/.test(this._curReq.fullcmd)) {
// FETCH response sent as result of FETCH request
const msg = this._curReq.fetchCache[info.num], keys = Object.keys(info.text), keyslen = keys.length
let toget, msgEmitter, j
Expand Down

0 comments on commit aa523b8

Please sign in to comment.