diff options
author | Karsten Loesing <karsten.loesing@gmx.net> | 2020-12-16 09:58:19 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2020-12-21 13:18:20 -0500 |
commit | 5dd6304f36a9cb9b7f778abe5b84cf6a4e9890a6 (patch) | |
tree | 8466c3e6f5d9a174bdd3fe7297ecea67e6d3fb03 /src/feature/relay/router.c | |
parent | c934fced31a2dd6d53b129b6270109bc48c1ebb0 (diff) | |
download | tor-5dd6304f36a9cb9b7f778abe5b84cf6a4e9890a6.tar.gz tor-5dd6304f36a9cb9b7f778abe5b84cf6a4e9890a6.zip |
Fix timestamp parser in new load_stats_file.
The previous parser only considered stats files _starting_ with the
timestamp tag, not stats files having the timestamp tag in a later
position. While this applies to all current stats files, a future
stats file might look differently. Better to fix the function now than
be surprised in another 9 years from now.
This commit also adds a test case for such future stats, and it fixes
stats file paths in newly added unit tests.
Diffstat (limited to 'src/feature/relay/router.c')
-rw-r--r-- | src/feature/relay/router.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c index abe23f9aae..e018561556 100644 --- a/src/feature/relay/router.c +++ b/src/feature/relay/router.c @@ -3176,12 +3176,12 @@ load_stats_file(const char *filename, const char *ts_tag, time_t now, goto end; } /* Do we have enough for parsing a timestamp? */ - if (strlen(contents) < strlen(ts_tag) + 1 + sizeof(timestr)) { + if (strlen(ts_tok) < strlen(ts_tag) + 1 + sizeof(timestr)) { log_warn(LD_BUG, "Token %s malformed in file %s", ts_tag, filename); goto end; } /* Parse timestamp in order to validate it is not too old. */ - strlcpy(timestr, contents + strlen(ts_tag) + 1, sizeof(timestr)); + strlcpy(timestr, ts_tok + strlen(ts_tag) + 1, sizeof(timestr)); if (parse_iso_time(timestr, &written) < 0) { log_warn(LD_BUG, "Token %s has a malformed timestamp in file %s", ts_tag, filename); |