diff options
author | corvid <corvid@lavabit.com> | 2010-01-20 03:16:35 +0000 |
---|---|---|
committer | corvid <corvid@lavabit.com> | 2010-01-20 03:16:35 +0000 |
commit | b0fd4b098a34f490c29abdbd8cecaed0ce545f83 (patch) | |
tree | 313e310dc5dcae89b49f4a02f7a33fb7d787cce8 /dpi/cookies.c | |
parent | 9f28a849f174d95aeead03d2be6c420c5f66fad3 (diff) |
cookies improve clock skew handling
Diffstat (limited to 'dpi/cookies.c')
-rw-r--r-- | dpi/cookies.c | 17 |
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; } } } |