summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/NsCookieParser.cc11
-rw-r--r--src/util.cc27
-rw-r--r--src/util.h4
3 files changed, 39 insertions, 3 deletions
diff --git a/src/NsCookieParser.cc b/src/NsCookieParser.cc
index e484df8e..77ca25ab 100644
--- a/src/NsCookieParser.cc
+++ b/src/NsCookieParser.cc
@@ -69,9 +69,14 @@ std::unique_ptr<Cookie> parseNsCookie(const std::string& cookieStr,
return nullptr;
}
int64_t expiryTime;
- if (!util::parseLLIntNoThrow(expiryTime,
- std::string(vs[4].first, vs[4].second))) {
- return nullptr;
+ {
+ // chrome extension uses subsecond resolution for expiry time.
+ double expiryTimeDouble;
+ if (!util::parseDoubleNoThrow(expiryTimeDouble,
+ std::string(vs[4].first, vs[4].second))) {
+ return nullptr;
+ }
+ expiryTime = static_cast<int64_t>(expiryTimeDouble);
}
if (std::numeric_limits<time_t>::max() < expiryTime) {
expiryTime = std::numeric_limits<time_t>::max();
diff --git a/src/util.cc b/src/util.cc
index a2590235..3c9c19b1 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -596,6 +596,33 @@ bool parseLLIntNoThrow(int64_t& res, const std::string& s, int base)
}
}
+bool parseDoubleNoThrow(double& res, const std::string& s)
+{
+ if (s.empty()) {
+ return false;
+ }
+
+ errno = 0;
+ char* endptr;
+ auto d = strtod(s.c_str(), &endptr);
+
+ if (errno == ERANGE) {
+ return false;
+ }
+
+ if (endptr != s.c_str() + s.size()) {
+ for (auto i = std::begin(s) + (endptr - s.c_str()); i != std::end(s); ++i) {
+ if (!isspace(*i)) {
+ return false;
+ }
+ }
+ }
+
+ res = d;
+
+ return true;
+}
+
SegList<int> parseIntSegments(const std::string& src)
{
SegList<int> sgl;
diff --git a/src/util.h b/src/util.h
index 25183b5c..76ecb549 100644
--- a/src/util.h
+++ b/src/util.h
@@ -280,6 +280,10 @@ bool parseUIntNoThrow(uint32_t& res, const std::string& s, int base = 10);
bool parseLLIntNoThrow(int64_t& res, const std::string& s, int base = 10);
+// Parses |s| as floating point number, and stores the result into
+// |res|. This function returns true if it succeeds.
+bool parseDoubleNoThrow(double& res, const std::string& s);
+
SegList<int> parseIntSegments(const std::string& src);
// Parses string which specifies the range of piece index for higher