summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcorvid <corvid@lavabit.com>2010-01-20 03:16:35 +0000
committercorvid <corvid@lavabit.com>2010-01-20 03:16:35 +0000
commitb0fd4b098a34f490c29abdbd8cecaed0ce545f83 (patch)
tree313e310dc5dcae89b49f4a02f7a33fb7d787cce8
parent9f28a849f174d95aeead03d2be6c420c5f66fad3 (diff)
cookies improve clock skew handling
-rw-r--r--dpi/cookies.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/dpi/cookies.c b/dpi/cookies.c
index 207e3bba..1d40ddf0 100644
--- a/dpi/cookies.c
+++ b/dpi/cookies.c
@@ -656,20 +656,17 @@ static time_t Cookies_expires_attr(char *value, const char *server_date)
time_t server_time = Cookies_create_timestamp(server_date);
if (server_time) {
- time_t now = time(NULL);
- time_t client_time = exptime + now - server_time;
+ time_t local_shift = time(NULL) - server_time;
- if (server_time == exptime) {
- exptime = now;
- } else if ((exptime > now) == (client_time > now)) {
- exptime = client_time;
- } else {
+ if ((exptime > 0 && local_shift > 0 && (exptime + local_shift < 0)) ||
+ (exptime < 0 && local_shift < 0 && (exptime + local_shift > 0))) {
/* Don't want to wrap around at the extremes of representable
* values thanks to clock skew.
*/
- MSG("At %ld, %ld was trying to turn into %ld\n",
- (long)now, (long)exptime,
- (long)client_time);
+ MSG("Time %ld was trying to turn into %ld\n", (long)exptime,
+ (long)(exptime + local_shift));
+ } else {
+ exptime += local_shift;
}
}
}