]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Terminate rep_hist_get_overload_stats_lines() with an NL. tor-0.4.6.1-alpha
authorNick Mathewson <nickm@torproject.org>
Thu, 18 Mar 2021 17:30:49 +0000 (13:30 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 18 Mar 2021 17:30:49 +0000 (13:30 -0400)
We use it in router.c, where chunks are joined with "", not with
NL... so leaving off the terminating NL will lead to an unparseable
extrainfo.

Found by toralf. Bug not in any released Tor.

src/feature/stats/rephist.c
src/test/test_stats.c

index 7c0c28804c8a7e3086477d6be6cca6deaeadf5f7..4ad5d46b0c92663453cc8bd6c3318dde0e33d915 100644 (file)
@@ -233,7 +233,7 @@ rep_hist_get_overload_stats_lines(void)
   /* First encode the general overload */
   if (overload_happened_recently(overload_stats.overload_general_time, 72)) {
     format_iso_time(tbuf, overload_stats.overload_general_time);
-    smartlist_add_asprintf(chunks, "overload-general %d %s",
+    smartlist_add_asprintf(chunks, "overload-general %d %s\n",
                            OVERLOAD_STATS_VERSION, tbuf);
   }
 
@@ -243,7 +243,7 @@ rep_hist_get_overload_stats_lines(void)
     format_iso_time(tbuf, overload_stats.overload_ratelimits_time);
     smartlist_add_asprintf(chunks,
                            "overload-ratelimits %d %s %" PRIu64 " %" PRIu64
-                           " %" PRIu64 " %" PRIu64,
+                           " %" PRIu64 " %" PRIu64 "\n",
                            OVERLOAD_STATS_VERSION, tbuf,
                            options->BandwidthRate, options->BandwidthBurst,
                            overload_stats.overload_read_count,
@@ -254,7 +254,7 @@ rep_hist_get_overload_stats_lines(void)
   if (overload_happened_recently(
                               overload_stats.overload_fd_exhausted_time, 72)) {
     format_iso_time(tbuf, overload_stats.overload_fd_exhausted_time);
-    smartlist_add_asprintf(chunks, "overload-fd-exhausted %d %s",
+    smartlist_add_asprintf(chunks, "overload-fd-exhausted %d %s\n",
                            OVERLOAD_STATS_VERSION, tbuf);
   }
 
@@ -263,7 +263,7 @@ rep_hist_get_overload_stats_lines(void)
     goto done;
   }
 
-  result = smartlist_join_strings(chunks, "\n", 0, NULL);
+  result = smartlist_join_strings(chunks, "", 0, NULL);
 
  done:
   SMARTLIST_FOREACH(chunks, char *, cp, tor_free(cp));
index a34713b650b15f586f0507b182e206937352711d..465256a1e17c6041d96d2aad60dcd85bdd0d78d8 100644 (file)
@@ -728,7 +728,7 @@ test_overload_stats(void *arg)
 
   /* Now check the string */
   stats_str = rep_hist_get_overload_stats_lines();
-  tt_str_op("overload-general 1 2002-01-03 23:00:00", OP_EQ, stats_str);
+  tt_str_op("overload-general 1 2002-01-03 23:00:00\n", OP_EQ, stats_str);
   tor_free(stats_str);
 
   /* Move the time forward 72 hours: see that the line has disappeared. */
@@ -744,7 +744,7 @@ test_overload_stats(void *arg)
   rep_hist_note_overload(OVERLOAD_GENERAL);
 
   stats_str = rep_hist_get_overload_stats_lines();
-  tt_str_op("overload-general 1 2002-01-07 00:00:00", OP_EQ, stats_str);
+  tt_str_op("overload-general 1 2002-01-07 00:00:00\n", OP_EQ, stats_str);
   tor_free(stats_str);
 
   /* Also note an fd exhaustion event */
@@ -752,7 +752,7 @@ test_overload_stats(void *arg)
 
   stats_str = rep_hist_get_overload_stats_lines();
   tt_str_op("overload-general 1 2002-01-07 00:00:00\n"
-            "overload-fd-exhausted 1 2002-01-07 00:00:00", OP_EQ, stats_str);
+            "overload-fd-exhausted 1 2002-01-07 00:00:00\n", OP_EQ, stats_str);
   tor_free(stats_str);
 
   /* Move the time forward. Register DNS overload. See that the time changed */
@@ -763,7 +763,7 @@ test_overload_stats(void *arg)
 
   stats_str = rep_hist_get_overload_stats_lines();
   tt_str_op("overload-general 1 2002-01-07 02:00:00\n"
-            "overload-fd-exhausted 1 2002-01-07 00:00:00", OP_EQ, stats_str);
+            "overload-fd-exhausted 1 2002-01-07 00:00:00\n", OP_EQ, stats_str);
   tor_free(stats_str);
 
   /* Move the time forward. Register a bandwidth ratelimit event. See that the
@@ -780,7 +780,7 @@ test_overload_stats(void *arg)
   stats_str = rep_hist_get_overload_stats_lines();
   tt_str_op("overload-general 1 2002-01-07 02:00:00\n"
             "overload-ratelimits 1 2002-01-07 04:00:00 1000 2000 1 0\n"
-            "overload-fd-exhausted 1 2002-01-07 00:00:00", OP_EQ, stats_str);
+            "overload-fd-exhausted 1 2002-01-07 00:00:00\n", OP_EQ, stats_str);
   tor_free(stats_str);
 
   /* Move the time forward 24 hours: no rate limit line anymore. */
@@ -789,7 +789,7 @@ test_overload_stats(void *arg)
 
   stats_str = rep_hist_get_overload_stats_lines();
   tt_str_op("overload-general 1 2002-01-07 02:00:00\n"
-            "overload-fd-exhausted 1 2002-01-07 00:00:00", OP_EQ, stats_str);
+            "overload-fd-exhausted 1 2002-01-07 00:00:00\n", OP_EQ, stats_str);
   tor_free(stats_str);
 
   /* Move the time forward 44 hours: no fd exhausted line anymore. */
@@ -797,7 +797,7 @@ test_overload_stats(void *arg)
   update_approx_time(current_time);
 
   stats_str = rep_hist_get_overload_stats_lines();
-  tt_str_op("overload-general 1 2002-01-07 02:00:00", OP_EQ, stats_str);
+  tt_str_op("overload-general 1 2002-01-07 02:00:00\n", OP_EQ, stats_str);
   tor_free(stats_str);
 
   /* Move the time forward 2 hours: there is nothing left. */
@@ -815,7 +815,7 @@ test_overload_stats(void *arg)
    * registered ten more overload events, but only one should have been counted
    * because of the rate limiter */
   stats_str = rep_hist_get_overload_stats_lines();
-  tt_str_op("overload-ratelimits 1 2002-01-10 02:00:00 1000 2000 2 0",
+  tt_str_op("overload-ratelimits 1 2002-01-10 02:00:00 1000 2000 2 0\n",
             OP_EQ, stats_str);
   tor_free(stats_str);
 
@@ -828,7 +828,7 @@ test_overload_stats(void *arg)
     rep_hist_note_overload(OVERLOAD_READ);
   }
   stats_str = rep_hist_get_overload_stats_lines();
-  tt_str_op("overload-ratelimits 1 2002-01-10 02:00:00 1000 2000 2 0",
+  tt_str_op("overload-ratelimits 1 2002-01-10 02:00:00 1000 2000 2 0\n",
             OP_EQ, stats_str);
   tor_free(stats_str);
 
@@ -842,7 +842,7 @@ test_overload_stats(void *arg)
     rep_hist_note_overload(OVERLOAD_WRITE);
   }
   stats_str = rep_hist_get_overload_stats_lines();
-  tt_str_op("overload-ratelimits 1 2002-01-10 02:00:00 1000 2000 3 1",
+  tt_str_op("overload-ratelimits 1 2002-01-10 02:00:00 1000 2000 3 1\n",
             OP_EQ, stats_str);
   tor_free(stats_str);