diff --git a/ChangeLog b/ChangeLog index f0758034..03602435 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-02-28 Tatsuhiro Tsujikawa + + Fixed the previous insufficient fix for possible busy loop. + * src/MSEHandshake.cc (identifyHandshakeType) + + Removed unused functions. + * src/MSEHandshake.{h, cc} (readDataAndDecrypt) + 2008-02-28 Tatsuhiro Tsujikawa Fixed possible busy loop if first 20 bytes are not received for a few diff --git a/src/MSEHandshake.cc b/src/MSEHandshake.cc index fe0d9060..d5fdd1e5 100644 --- a/src/MSEHandshake.cc +++ b/src/MSEHandshake.cc @@ -91,9 +91,12 @@ MSEHandshake::HANDSHAKE_TYPE MSEHandshake::identifyHandshakeType() if(!_socket->isReadable(0)) { return HANDSHAKE_NOT_YET; } - int32_t bufLength = 20-_rbufLength; - _socket->readData(_rbuf+_rbufLength, bufLength); - _rbufLength += bufLength; + int32_t r = 20-_rbufLength; + _socket->readData(_rbuf+_rbufLength, r); + if(r == 0) { + throw new DlAbortEx(EX_EOF_FROM_PEER); + } + _rbufLength += r; if(_rbufLength < 20) { return HANDSHAKE_NOT_YET; } @@ -180,16 +183,6 @@ void MSEHandshake::initCipher(const unsigned char* infoHash) } } -ssize_t MSEHandshake::readDataAndDecrypt(unsigned char* data, size_t length) -{ - unsigned char temp[MAX_BUFFER_LENGTH]; - assert(MAX_BUFFER_LENGTH >= length); - int32_t rlength = length; - _socket->readData(temp, rlength); - _decryptor->decrypt(data, rlength, temp, rlength); - return rlength; -} - void MSEHandshake::encryptAndSendData(const unsigned char* data, size_t length) { unsigned char temp[4096]; diff --git a/src/MSEHandshake.h b/src/MSEHandshake.h index 13771d95..8a416d34 100644 --- a/src/MSEHandshake.h +++ b/src/MSEHandshake.h @@ -102,8 +102,6 @@ private: static const unsigned char VC[VC_LENGTH]; - ssize_t readDataAndDecrypt(unsigned char* data, size_t length); - void encryptAndSendData(const unsigned char* data, size_t length); void createReq1Hash(unsigned char* md) const;