Browse Source

avoid calling format_iso_time() with TIME_MAX

If we tried to move a descriptor from routerlist->old_routers
back into the current routerlist, we were preparing a buffer with
format_iso_time() on ri->cert_expiration_time, and doing it preemptively
since router_add_to_routerlist() might free ri so we wouldn't be able
to get at it later in the function.

But if the descriptor we're moving doesn't have any ed signature, then
its cert will be marked to expire at TIME_MAX, and handing TIME_MAX
to format_iso_time() generates this log warning:

correct_tm(): Bug: gmtime(9223372036854775807) failed with error Value too large for defined data type: Rounding down to 2037

The fix is to preemptively remember the expiry time, but only prepare
the buffer if we know we're going to need it.

Bugfix on commit a1b0a0b9, which came about as part of a fix for bug
20020, and which is not yet in any released version of Tor (hence no
changes file).
Roger Dingledine 6 years ago
parent
commit
40cd992abb
1 changed files with 5 additions and 3 deletions
  1. 5 3
      src/or/routerlist.c

+ 5 - 3
src/or/routerlist.c

@@ -5207,14 +5207,14 @@ update_consensus_router_descriptor_downloads(time_t now, int is_vote,
     SMARTLIST_FOREACH_BEGIN(no_longer_old, signed_descriptor_t *, sd) {
         const char *msg;
         was_router_added_t r;
+        time_t tmp_cert_expiration_time;
         routerinfo_t *ri = routerlist_reparse_old(rl, sd);
         if (!ri) {
           log_warn(LD_BUG, "Failed to re-parse a router.");
           continue;
         }
-        /* need to compute this now, since add_to_routerlist may free. */
-        char time_cert_expires[ISO_TIME_LEN+1];
-        format_iso_time(time_cert_expires, ri->cert_expiration_time);
+        /* need to remember for below, since add_to_routerlist may free. */
+        tmp_cert_expiration_time = ri->cert_expiration_time;
 
         r = router_add_to_routerlist(ri, &msg, 1, 0);
         if (WRA_WAS_OUTDATED(r)) {
@@ -5224,7 +5224,9 @@ update_consensus_router_descriptor_downloads(time_t now, int is_vote,
                    msg?msg:"???");
           if (r == ROUTER_CERTS_EXPIRED) {
             char time_cons[ISO_TIME_LEN+1];
+            char time_cert_expires[ISO_TIME_LEN+1];
             format_iso_time(time_cons, consensus->valid_after);
+            format_iso_time(time_cert_expires, tmp_cert_expiration_time);
             log_warn(LD_DIR, "  (I'm looking at a consensus from %s; This "
                      "router's certificates began expiring at %s.)",
                      time_cons, time_cert_expires);