Просмотр исходного кода

2009-06-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Throw an exception if position is less than 0.
	* src/XmlRpcMethodImpl.cc
	* test/XmlRpcMethodTest.cc
Tatsuhiro Tsujikawa 16 лет назад
Родитель
Сommit
a28f19befb
3 измененных файлов с 26 добавлено и 2 удалено
  1. 6 0
      ChangeLog
  2. 6 2
      src/XmlRpcMethodImpl.cc
  3. 14 0
      test/XmlRpcMethodTest.cc

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+2009-06-14  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Throw an exception if position is less than 0.
+	* src/XmlRpcMethodImpl.cc
+	* test/XmlRpcMethodTest.cc
+
 2009-06-14  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Use writeFilePath() in ConsoleStatCalc.cc

+ 6 - 2
src/XmlRpcMethodImpl.cc

@@ -102,8 +102,12 @@ static void getPosParam(const BDE& params, size_t posParamIndex,
 			bool& posGiven, size_t& pos)
 {
   if(params.size() > posParamIndex && params[posParamIndex].isInteger()) {
-    pos = params[posParamIndex].i();
-    posGiven = true;
+    if(params[posParamIndex].i() >= 0) {
+      pos = params[posParamIndex].i();
+      posGiven = true;
+    } else {
+      throw DL_ABORT_EX("Position must be greater than or equal to 0.");
+    }
   } else {
     posGiven = false;
   }

+ 14 - 0
test/XmlRpcMethodTest.cc

@@ -30,6 +30,7 @@ class XmlRpcMethodTest:public CppUnit::TestFixture {
   CPPUNIT_TEST(testAddUri_notUri);
   CPPUNIT_TEST(testAddUri_withBadOption);
   CPPUNIT_TEST(testAddUri_withPosition);
+  CPPUNIT_TEST(testAddUri_withBadPosition);
 #ifdef ENABLE_BITTORRENT
   CPPUNIT_TEST(testAddTorrent);
   CPPUNIT_TEST(testAddTorrent_withoutTorrent);
@@ -73,6 +74,7 @@ public:
   void testAddUri_notUri();
   void testAddUri_withBadOption();
   void testAddUri_withPosition();
+  void testAddUri_withBadPosition();
 #ifdef ENABLE_BITTORRENT
   void testAddTorrent();
   void testAddTorrent_withoutTorrent();
@@ -178,6 +180,18 @@ void XmlRpcMethodTest::testAddUri_withPosition()
   CPPUNIT_ASSERT_EQUAL(std::string("http://uri2"), uri);
 }
 
+void XmlRpcMethodTest::testAddUri_withBadPosition()
+{
+  AddUriXmlRpcMethod m;
+  XmlRpcRequest req("aria2.addUri", BDE::list());
+  req._params << BDE::list();
+  req._params[0] << BDE("http://localhost/");
+  req._params << BDE::dict();
+  req._params << BDE((int64_t)-1);
+  XmlRpcResponse res = m.execute(req, _e.get());
+  CPPUNIT_ASSERT_EQUAL(1, res._code);
+}
+
 #ifdef ENABLE_BITTORRENT
 void XmlRpcMethodTest::testAddTorrent()
 {