From 1e63b1cda511542c2085624d76ae81778e596230 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 15 Dec 2007 14:34:31 +0000 Subject: [PATCH] 2007-12-15 Tatsuhiro Tsujikawa Fixed the bug that prevents aria2 from loading cookie file when expire value is greater than 2^31-1. BUG#1851066 * src/CookieBoxFactory.cc * test/CookieBoxFactoryTest.cc --- ChangeLog | 7 +++++++ src/CookieBoxFactory.cc | 20 ++++++++++++++++---- test/CookieBoxFactoryTest.cc | 14 +++++++++++++- test/nscookietest.txt | 5 +++-- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4d901225..ccf5f483 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-12-15 Tatsuhiro Tsujikawa + + Fixed the bug that prevents aria2 from loading cookie file when expire + value is greater than 2^31-1. BUG#1851066 + * src/CookieBoxFactory.cc + * test/CookieBoxFactoryTest.cc + 2007-12-14 Tatsuhiro Tsujikawa Fixed possible memory leak when an exception is thrown. diff --git a/src/CookieBoxFactory.cc b/src/CookieBoxFactory.cc index 2020d5b4..6197a349 100644 --- a/src/CookieBoxFactory.cc +++ b/src/CookieBoxFactory.cc @@ -35,6 +35,7 @@ #include "CookieBoxFactory.h" #include "CookieParser.h" #include "Util.h" +#include "RecoverableException.h" CookieBoxHandle CookieBoxFactory::createNewInstance() { @@ -50,9 +51,15 @@ void CookieBoxFactory::loadDefaultCookie(istream& s) if(Util::startsWith(line, "#")) { continue; } - Cookie c = parseNsCookie(line); - if(c.good()) { - defaultCookies.push_back(c); + try { + Cookie c = parseNsCookie(line); + if(c.good()) { + defaultCookies.push_back(c); + } + } catch(RecoverableException* e) { + // ignore malformed cookie entry + // TODO better to log it + delete e; } } } @@ -68,7 +75,12 @@ Cookie CookieBoxFactory::parseNsCookie(const string& nsCookieStr) const c.domain = vs[0]; c.path = vs[2]; c.secure = vs[3] == "TRUE" ? true : false; - c.expires = Util::parseInt(vs[4]); + int64_t expireDate = Util::parseLLInt(vs[4]); + // TODO assuming time_t is int32_t... + if(expireDate > INT32_MAX) { + expireDate = INT32_MAX; + } + c.expires = expireDate; c.name = vs[5]; if(vs.size() >= 7) { c.value = vs[6]; diff --git a/test/CookieBoxFactoryTest.cc b/test/CookieBoxFactoryTest.cc index 17e2ed47..5c5a6da6 100644 --- a/test/CookieBoxFactoryTest.cc +++ b/test/CookieBoxFactoryTest.cc @@ -38,18 +38,30 @@ void CookieBoxFactoryTest::testLoadDefaultCookie() Cookie c = cookies[0]; CPPUNIT_ASSERT_EQUAL(string("JSESSIONID"), c.name); CPPUNIT_ASSERT_EQUAL(string("123456789"), c.value); + CPPUNIT_ASSERT_EQUAL((time_t)1181473200, c.expires); + CPPUNIT_ASSERT_EQUAL(string("/"), c.path); + CPPUNIT_ASSERT_EQUAL(string("localhost"), c.domain); c = cookies[1]; CPPUNIT_ASSERT_EQUAL(string("user"), c.name); CPPUNIT_ASSERT_EQUAL(string("me"), c.value); + CPPUNIT_ASSERT_EQUAL((time_t)1181473200, c.expires); + CPPUNIT_ASSERT_EQUAL(string("/"), c.path); + CPPUNIT_ASSERT_EQUAL(string("localhost"), c.domain); c = cookies[2]; CPPUNIT_ASSERT_EQUAL(string("passwd"), c.name); CPPUNIT_ASSERT_EQUAL(string("secret"), c.value); + CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires); + CPPUNIT_ASSERT_EQUAL(string("/cgi-bin"), c.path); + CPPUNIT_ASSERT_EQUAL(string("localhost"), c.domain); c = cookies[3]; CPPUNIT_ASSERT_EQUAL(string("novalue"), c.name); CPPUNIT_ASSERT_EQUAL(string(""), c.value); + CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires); + CPPUNIT_ASSERT_EQUAL(string("/"), c.path); + CPPUNIT_ASSERT_EQUAL(string("localhost"), c.domain); } void CookieBoxFactoryTest::testCreateNewInstance() @@ -60,5 +72,5 @@ void CookieBoxFactoryTest::testCreateNewInstance() CookieBoxHandle box = factory.createNewInstance(); Cookies cookies = box->criteriaFind("localhost", "/", 0, true); - CPPUNIT_ASSERT_EQUAL((int32_t)4, (int32_t)cookies.size()); + CPPUNIT_ASSERT_EQUAL((int32_t)3, (int32_t)cookies.size()); } diff --git a/test/nscookietest.txt b/test/nscookietest.txt index 5f31b1d4..09cf7dc5 100644 --- a/test/nscookietest.txt +++ b/test/nscookietest.txt @@ -3,5 +3,6 @@ localhost FALSE / TRUE 1181473200 JSESSIONID 123456789 localhost FALSE / FALSE 1181473200 user me -localhost FALSE / FALSE 1181473200 passwd secret -localhost FALSE / FALSE 1181473200 novalue \ No newline at end of file +localhost FALSE /cgi-bin FALSE 2147483647 passwd secret +overflow FALSE / FALSE FALSE 9223372036854775807 TAX 1000 +localhost FALSE / FALSE 2147483648 novalue \ No newline at end of file