Browse Source

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
Tatsuhiro Tsujikawa 17 năm trước cách đây
mục cha
commit
2040d64fe5
5 tập tin đã thay đổi với 53 bổ sung6 xóa
  1. 11 0
      ChangeLog
  2. 2 0
      src/BtConstants.h
  3. 5 2
      src/PeerMessageUtil.cc
  4. 0 2
      src/PeerMessageUtil.h
  5. 35 2
      test/BtRequestMessageTest.cc

+ 11 - 0
ChangeLog

@@ -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

+ 2 - 0
src/BtConstants.h

@@ -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_

+ 5 - 2
src/PeerMessageUtil.cc

@@ -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 {
 

+ 0 - 2
src/PeerMessageUtil.h

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

+ 35 - 2
test/BtRequestMessageTest.cc

@@ -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