changeset 1527:03752405e0a9

cookies improve clock skew handling
author corvid <corvid@lavabit.com>
date Wed, 20 Jan 2010 03:16:35 +0000
parents e7571ffc35e1
children d72793539000
files dpi/cookies.c
diffstat 1 files changed, 7 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/dpi/cookies.c	Wed Jan 20 00:08:25 2010 +0000
+++ b/dpi/cookies.c	Wed Jan 20 03:16:35 2010 +0000
@@ -656,20 +656,17 @@
       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;
          }
       }
    }