diff options
-rw-r--r-- | src/or/geoip.c | 4 | ||||
-rw-r--r-- | src/or/router.c | 21 |
2 files changed, 13 insertions, 12 deletions
diff --git a/src/or/geoip.c b/src/or/geoip.c index b2a47aa68f..ae0776a571 100644 --- a/src/or/geoip.c +++ b/src/or/geoip.c @@ -289,7 +289,9 @@ geoip_is_loaded(void) return geoip_countries != NULL && geoip_entries != NULL; } -/** Return the hex-encoded SHA1 digest of the loaded GeoIP file. */ +/** Return the hex-encoded SHA1 digest of the loaded GeoIP file. The + * result does not need to be deallocated, but will be overwritten by the + * next call of hex_str(). */ const char * geoip_db_digest(void) { diff --git a/src/or/router.c b/src/or/router.c index 85300a3186..4d3c66f4d5 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -2012,20 +2012,19 @@ extrainfo_dump_to_string(char *s, size_t maxlen, extrainfo_t *extrainfo, if (result<0) return -1; + if (geoip_is_loaded()) { + if (tor_snprintf(s + strlen(s), maxlen - strlen(s), + "geoip-db-digest %s\n", + geoip_db_digest()) < 0) { + log_warn(LD_DIR, "Could not write geoip-db-digest to extra-info " + "descriptor."); + return -1; + } + } + if (options->ExtraInfoStatistics && write_stats_to_extrainfo) { char *contents = NULL; log_info(LD_GENERAL, "Adding stats to extra-info descriptor."); - if (geoip_is_loaded()) { - size_t pos = strlen(s); - if (tor_snprintf(s + pos, maxlen - strlen(s), - "geoip-db-digest %s\n", - geoip_db_digest()) < 0) { - log_warn(LD_DIR, "Could not write geoip-db-digest to extra-info " - "descriptor."); - s[pos] = '\0'; - write_stats_to_extrainfo = 0; - } - } if (options->DirReqStatistics && load_stats_file("stats"PATH_SEPARATOR"dirreq-stats", "dirreq-stats-end", now, &contents) > 0) { |