2008-10-19 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Fixed the bug that aria2 aborts when a request larger than 16KiB 
is
	recieved.
	In this fix, if a request larger than 16KiB length is received, 
aria2
	disconnects the peer.
	* src/BtConstants.h
	* src/PeerMessageUtil.cc
	* src/PeerMessageUtil.h
	* test/BtRequestMessageTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-10-19 14:53:30 +00:00
parent ff20aefa51
commit 2040d64fe5
5 changed files with 53 additions and 6 deletions

View File

@ -1,3 +1,14 @@
2008-10-19 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed the bug that aria2 aborts when a request larger than 16KiB is
recieved.
In this fix, if a request larger than 16KiB length is received, aria2
disconnects the peer.
* src/BtConstants.h
* src/PeerMessageUtil.cc
* src/PeerMessageUtil.h
* test/BtRequestMessageTest.cc
2008-10-14 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* Release 0.16.1

View File

@ -47,4 +47,6 @@ typedef std::map<std::string, uint8_t> Extensions;
#define DEFAULT_LATENCY 1500
#define MAX_BLOCK_LENGTH (16*1024)
#endif // _D_BT_CONSTANTS_

View File

@ -33,11 +33,14 @@
*/
/* copyright --> */
#include "PeerMessageUtil.h"
#include <cassert>
#include <cstring>
#include "DlAbortEx.h"
#include "a2netcompat.h"
#include "StringFormat.h"
#include <cassert>
#include <cstring>
#include "BtConstants.h"
namespace aria2 {

View File

@ -41,8 +41,6 @@
namespace aria2 {
#define MAX_BLOCK_LENGTH (128*1024)
class PeerMessageUtil {
private:
PeerMessageUtil() {}

View File

@ -1,4 +1,9 @@
#include "BtRequestMessage.h"
#include <cstring>
#include <cppunit/extensions/HelperMacros.h>
#include "PeerMessageUtil.h"
#include "MockBtContext.h"
#include "MockBtMessage.h"
@ -16,8 +21,7 @@
#include "ExtensionMessageFactory.h"
#include "FileEntry.h"
#include "BtHandshakeMessage.h"
#include <cstring>
#include <cppunit/extensions/HelperMacros.h>
#include "BtRequestMessageValidator.h"
namespace aria2 {
@ -36,6 +40,8 @@ class BtRequestMessageTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testHandleAbortRequestEvent_alreadyInvalidated);
CPPUNIT_TEST(testHandleAbortRequestEvent_sendingInProgress);
CPPUNIT_TEST(testToString);
CPPUNIT_TEST(testValidate);
CPPUNIT_TEST(testValidate_lengthTooLong);
CPPUNIT_TEST_SUITE_END();
private:
@ -52,6 +58,8 @@ public:
void testHandleAbortRequestEvent_alreadyInvalidated();
void testHandleAbortRequestEvent_sendingInProgress();
void testToString();
void testValidate();
void testValidate_lengthTooLong();
class MockPieceStorage2 : public MockPieceStorage {
public:
@ -283,4 +291,29 @@ void BtRequestMessageTest::testToString() {
msg->toString());
}
void BtRequestMessageTest::testValidate() {
BtRequestMessage msg(0, 0, 16*1024);
msg.setBtMessageValidator
(SharedHandle<BtMessageValidator>
(new BtRequestMessageValidator(&msg, 1024, 256*1024)));
std::deque<std::string> errors;
msg.validate(errors);
}
void BtRequestMessageTest::testValidate_lengthTooLong() {
BtRequestMessage msg(0, 0, 16*1024+1);
msg.setBtMessageValidator
(SharedHandle<BtMessageValidator>
(new BtRequestMessageValidator(&msg, 1024, 256*1024)));
std::deque<std::string> errors;
try {
msg.validate(errors);
CPPUNIT_FAIL("exception must be thrown.");
} catch(DlAbortEx& e) {
CPPUNIT_ASSERT_EQUAL(std::string("Length too long: 16385 > 16KB"),
std::string(e.what()));
}
}
} // namespace aria2