From 32da3d9dae5d1a54cdb49ce26ad7051f6494c2bc Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sun, 19 Jan 2014 12:01:36 +0100 Subject: [PATCH] Cookies: avoid timezone confusion Cookies date are always in GMT time. Using mktime wrongly converts them as local time instead. This would lead to cookies expiring too early or too late. --- src/kits/network/libnetapi/HttpTime.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/kits/network/libnetapi/HttpTime.cpp b/src/kits/network/libnetapi/HttpTime.cpp index b963f95dc6..ecc9c15155 100644 --- a/src/kits/network/libnetapi/HttpTime.cpp +++ b/src/kits/network/libnetapi/HttpTime.cpp @@ -107,7 +107,11 @@ BHttpTime::Parse() // TODO: The above was used initially. See http://en.wikipedia.org/wiki/Time.h // stippi: I don't know how Christophe had this code compiling initially, // since Haiku does not appear to implement timegm(). -return mktime(&expireTime); +// Using mktime() doesn't cut it, as cookies set with a date shortly in the +// future (eg. 1 hour) would expire immediately. + time_t t = mktime(&expireTime); + t -= mktime(gmtime(&t)) - (int)mktime(localtime(&t)); + return t; }