ditesh / node-poplib

POP3 client library for Node.js
MIT License
128 stars 44 forks source link

POP3Client.prototype.uidl - infinite loop #1

Closed nazar closed 13 years ago

nazar commented 13 years ago

Hi Ditesh.

Thank you for the library.

I've encountered a situation where POP3Client.prototype.uidl get stuck in a loop.

                        while(true) {

                            if ( (offset > endOffset) break;

                            newoffset = data.indexOf("\r\n", offset);
                            listitem = data.substr(offset, newoffset-offset);
                            listitem = listitem.split(" ");
                            returnValue[listitem[0]] = listitem[1];
                            offset = newoffset + 2;

                        }

the (offset > endOffSet) is never met as when the last item is added offset is smaller than endOffset.

I patched it as follows:

                        while(true) {

                            if ( (offset > endOffset) || (newoffset == -1) ) break;

                            newoffset = data.indexOf("\r\n", offset);
                            listitem = data.substr(offset, newoffset-offset);
                            listitem = listitem.split(" ");
                            returnValue[listitem[0]] = listitem[1];
                            offset = newoffset + 2;

                        }

There might be a better way.

HTH

ditesh commented 13 years ago

Thanks for the feedback. I've committed a fix.

Could you help test out commit https://github.com/ditesh/node-poplib/commit/269e36fb57660caf56152b7ba9d041906eb51932 ?

ditesh commented 13 years ago

Released 0.1.4, with several other fixes.