mirror of https://github.com/aria2/aria2
2010-10-26 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Use std::numeric_limits<time_t> instead of checking of sizeof(time_t). * src/NsCookieParser.cc * src/Sqlite3CookieParser.cc * src/cookie_helper.cc * test/CookieHelperTest.cc * test/CookieStorageTest.cc * test/NsCookieParserTest.ccpull/1/head
parent
5eec87df03
commit
423ec26fe4
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2010-10-26 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Use std::numeric_limits<time_t> instead of checking of
|
||||
sizeof(time_t).
|
||||
* src/NsCookieParser.cc
|
||||
* src/Sqlite3CookieParser.cc
|
||||
* src/cookie_helper.cc
|
||||
* test/CookieHelperTest.cc
|
||||
* test/CookieStorageTest.cc
|
||||
* test/NsCookieParserTest.cc
|
||||
|
||||
2010-10-26 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Fixed improper use of vsnprintf
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "NsCookieParser.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
|
||||
#include "util.h"
|
||||
#include "A2STR.h"
|
||||
|
@ -70,12 +71,15 @@ bool parseNsCookie
|
|||
if(!util::parseLLIntNoThrow(expiryTime, vs[4])) {
|
||||
return false;
|
||||
}
|
||||
if(sizeof(time_t) == 4 && expiryTime > INT32_MAX) {
|
||||
expiryTime = INT32_MAX;
|
||||
if(std::numeric_limits<time_t>::max() < expiryTime) {
|
||||
expiryTime = std::numeric_limits<time_t>::max();
|
||||
} else if(std::numeric_limits<time_t>::min() > expiryTime) {
|
||||
expiryTime = std::numeric_limits<time_t>::min();
|
||||
}
|
||||
cookie.setName(vs[5]);
|
||||
cookie.setValue(vs.size() >= 7? vs[6]:A2STR::NIL);
|
||||
cookie.setExpiryTime(expiryTime == 0?INT32_MAX:expiryTime);
|
||||
cookie.setExpiryTime(expiryTime == 0?
|
||||
std::numeric_limits<time_t>::max():expiryTime);
|
||||
// aria2 treats expiryTime == 0 means session cookie.
|
||||
cookie.setPersistent(expiryTime != 0);
|
||||
cookie.setDomain(cookieDomain);
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "Sqlite3CookieParser.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
|
||||
#include "DlAbortEx.h"
|
||||
#include "util.h"
|
||||
|
@ -83,8 +84,10 @@ static bool parseTime(int64_t& time, const std::string& s)
|
|||
if(!util::parseLLIntNoThrow(time, s)) {
|
||||
return false;
|
||||
}
|
||||
if(sizeof(time_t) == 4 && time > INT32_MAX) {
|
||||
time = INT32_MAX;
|
||||
if(std::numeric_limits<time_t>::max() < time) {
|
||||
time = std::numeric_limits<time_t>::max();
|
||||
} else if(std::numeric_limits<time_t>::min() > time) {
|
||||
time = std::numeric_limits<time_t>::min();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <limits>
|
||||
|
||||
#include "util.h"
|
||||
#include "array_fun.h"
|
||||
|
@ -263,8 +264,8 @@ bool parse
|
|||
} else {
|
||||
int64_t n = creationTime;
|
||||
n += delta;
|
||||
if(n < 0 || (sizeof(time_t) < 8 && n > INT32_MAX)) {
|
||||
maxAge = INT32_MAX;
|
||||
if(n < 0 || std::numeric_limits<time_t>::max() < n) {
|
||||
maxAge = std::numeric_limits<time_t>::max();
|
||||
} else {
|
||||
maxAge = n;
|
||||
}
|
||||
|
@ -302,7 +303,7 @@ bool parse
|
|||
} else if(foundExpires) {
|
||||
persistent = true;
|
||||
} else {
|
||||
expiryTime = INT32_MAX;
|
||||
expiryTime = std::numeric_limits<time_t>::max();
|
||||
persistent = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "cookie_helper.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
#include "Exception.h"
|
||||
|
@ -123,7 +125,7 @@ void CookieHelperTest::testParse()
|
|||
std::string str = "id=; Max-Age=9223372036854775807;";
|
||||
Cookie c;
|
||||
CPPUNIT_ASSERT(cookie::parse(c, str, "localhost", "/", creationDate));
|
||||
CPPUNIT_ASSERT_EQUAL((time_t)INT32_MAX, c.getExpiryTime());
|
||||
CPPUNIT_ASSERT_EQUAL(std::numeric_limits<time_t>::max(), c.getExpiryTime());
|
||||
CPPUNIT_ASSERT(c.getPersistent());
|
||||
}
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
|
@ -269,7 +270,7 @@ void CookieStorageTest::testLoad()
|
|||
Cookie c = cookies[0];
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("passwd"), c.getName());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("secret"), c.getValue());
|
||||
CPPUNIT_ASSERT_EQUAL((time_t)INT32_MAX, c.getExpiryTime());
|
||||
CPPUNIT_ASSERT_EQUAL(std::numeric_limits<time_t>::max(), c.getExpiryTime());
|
||||
CPPUNIT_ASSERT(!c.getPersistent());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/cgi-bin"), c.getPath());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), c.getDomain());
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "NsCookieParser.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
|
@ -58,7 +59,7 @@ void NsCookieParserTest::testParse()
|
|||
c = cookies[2];
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("passwd"), c.getName());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("secret"), c.getValue());
|
||||
CPPUNIT_ASSERT_EQUAL((time_t)INT32_MAX, c.getExpiryTime());
|
||||
CPPUNIT_ASSERT_EQUAL(std::numeric_limits<time_t>::max(), c.getExpiryTime());
|
||||
CPPUNIT_ASSERT(!c.getPersistent());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), c.getDomain());
|
||||
CPPUNIT_ASSERT(c.getHostOnly());
|
||||
|
|
Loading…
Reference in New Issue