From a28f19befb3d77ad4b512e1a32e23fec03e801d4 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 14 Jun 2009 11:29:46 +0000 Subject: [PATCH] 2009-06-14 Tatsuhiro Tsujikawa Throw an exception if position is less than 0. * src/XmlRpcMethodImpl.cc * test/XmlRpcMethodTest.cc --- ChangeLog | 6 ++++++ src/XmlRpcMethodImpl.cc | 8 ++++++-- test/XmlRpcMethodTest.cc | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1261481d..94eeaa8c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-06-14 Tatsuhiro Tsujikawa + + Throw an exception if position is less than 0. + * src/XmlRpcMethodImpl.cc + * test/XmlRpcMethodTest.cc + 2009-06-14 Tatsuhiro Tsujikawa Use writeFilePath() in ConsoleStatCalc.cc diff --git a/src/XmlRpcMethodImpl.cc b/src/XmlRpcMethodImpl.cc index 6f627de1..a29c2448 100644 --- a/src/XmlRpcMethodImpl.cc +++ b/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; } diff --git a/test/XmlRpcMethodTest.cc b/test/XmlRpcMethodTest.cc index e2ee26ff..41f02f5b 100644 --- a/test/XmlRpcMethodTest.cc +++ b/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() {