Terminate rep_hist_get_overload_stats_lines() with an NL.

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.
This commit is contained in:
Nick Mathewson 2021-03-18 13:30:49 -04:00
parent 411db63fc3
commit cd0e5a942e
2 changed files with 14 additions and 14 deletions

View 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));

View 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);