[or-cvs] [tor/master] Fix bugs with assuming time_t can be implicitly cast to long

nickm at torproject.org nickm at torproject.org
Wed Jun 30 00:14:37 UTC 2010


Author: Nick Mathewson <nickm at torproject.org>
Date: Tue, 29 Jun 2010 19:55:10 -0400
Subject: Fix bugs with assuming time_t can be implicitly cast to long
Commit: 741ab2a47abeba41223b908a71f10c80d6c18b6e

Many friendly operating systems have 64-bit times, and it's not nice
to pass them to an %ld format.

It's also extremely not-nice to write a time to the log as an
integer.  Most people think it's 2010 June 29 23:57 UTC+epsilon, not
1277855805+epsilon.
---
 src/or/circuitbuild.c |   12 +++++++++---
 src/or/circuituse.c   |    9 +++++----
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 1d654f0..6ee2921 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -946,11 +946,17 @@ circuit_build_times_network_close(circuit_build_times_t *cbt,
   if (cbt->liveness.network_last_live <= start_time &&
           start_time <= (now - cbt->close_ms/1000.0)) {
     if (did_onehop) {
+      char last_live_buf[ISO_TIME_LEN+1];
+      char start_time_buf[ISO_TIME_LEN+1];
+      char now_buf[ISO_TIME_LEN+1];
+      format_local_iso_time(last_live_buf, cbt->liveness.network_last_live);
+      format_local_iso_time(start_time_buf, start_time);
+      format_local_iso_time(now_buf, now);
       log_warn(LD_BUG,
                "Circuit somehow completed a hop while the network was "
-               "not live. Network was last live at %ld, but circuit launched "
-               "at %ld. It's now %ld.", cbt->liveness.network_last_live,
-               start_time, now);
+               "not live. Network was last live at %s, but circuit launched "
+               "at %s. It's now %s.", last_live_buf, start_time_buf,
+               now_buf);
     }
     cbt->liveness.nonlive_timeouts++;
   }
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index c1b39b1..50800ae 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -381,7 +381,8 @@ circuit_expire_building(time_t now)
       if (now - victim->timestamp_created > 2*circ_times.close_ms/1000+1) {
         log_notice(LD_CIRC,
                    "Extremely large value for circuit build timeout: %lds. "
-                   "Assuming clock jump.", now - victim->timestamp_created);
+                   "Assuming clock jump.",
+                   (long)(now - victim->timestamp_created));
       } else if (circuit_build_times_count_close(&circ_times,
                                           first_hop_succeeded,
                                           victim->timestamp_created)) {
@@ -727,15 +728,15 @@ circuit_expire_old_circuits_clientside(time_t now)
                 circ->purpose <= CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED) ||
                 circ->purpose == CIRCUIT_PURPOSE_S_CONNECT_REND) {
           log_debug(LD_CIRC,
-                    "Closing circuit that has been unused for %d seconds.",
-                    (int)(now - circ->timestamp_created));
+                    "Closing circuit that has been unused for %ld seconds.",
+                    (long)(now - circ->timestamp_created));
           circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
         } else if (!TO_ORIGIN_CIRCUIT(circ)->is_ancient) {
           log_notice(LD_CIRC,
                      "Ancient non-dirty circuit %d is still around after "
                      "%ld seconds. Purpose: %d",
                      TO_ORIGIN_CIRCUIT(circ)->global_identifier,
-                     now - circ->timestamp_created,
+                     (long)(now - circ->timestamp_created),
                      circ->purpose);
           TO_ORIGIN_CIRCUIT(circ)->is_ancient = 1;
         }
-- 
1.7.1



More information about the tor-commits mailing list