summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-03-11 02:21:30 +0000
committerNick Mathewson <nickm@torproject.org>2006-03-11 02:21:30 +0000
commit4d3e709c4bb615c8988c864d7b7a692e5cf89964 (patch)
tree1a9004fdc7b4d51173317379e634bd01291056ab
parent86a72f73b92a15865b5a2f19374d7243d55edc00 (diff)
downloadtor-4d3e709c4bb615c8988c864d7b7a692e5cf89964.tar.gz
tor-4d3e709c4bb615c8988c864d7b7a692e5cf89964.zip
Use escaped() for remaining cases.
svn:r6117
-rw-r--r--doc/TODO4
-rw-r--r--src/common/util.c4
-rw-r--r--src/or/dirserv.c20
-rw-r--r--src/or/or.h1
-rw-r--r--src/or/routerlist.c22
5 files changed, 38 insertions, 13 deletions
diff --git a/doc/TODO b/doc/TODO
index eca1e759de..515bc89243 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -50,8 +50,8 @@ N - building on freebsd 6.0: (with multiple openssl installations)
are dangerous for our users.
o So... add functions to escape potentially malicious values before
logging them, and test values more closely as they arrive...
- - But what to do about contact_info and platform?
- - (Didn't finish converting rend*.c)
+ o But what to do about contact_info and platform?
+ o (Didn't finish converting rend*.c)
for 0.1.1.x-final:
- find 10 dirservers.
diff --git a/src/common/util.c b/src/common/util.c
index 4975dfa917..3055ac2750 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -592,6 +592,10 @@ esc_for_log(const char *s)
const char *cp;
char *result, *outp;
size_t len = 3;
+ if (!s) {
+ return tor_strdup("");
+ }
+
for (cp = s; *cp; ++cp) {
switch (*cp) {
case '\\':
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index e197477231..0ae6ed6c65 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -347,12 +347,14 @@ dirserv_get_status_impl(const char *fp, const char *nickname,
return FP_NAMED; /* Right fingerprint. */
} else {
if (should_log) {
+ char *esc_contact = esc_for_log(contact);
log_warn(LD_DIRSERV,
"Mismatched fingerprint for '%s': expected '%s' got '%s'. "
"ContactInfo '%s', platform '%s'.)",
nickname, nn_ent->fingerprint, fp,
- contact ? contact : "",
+ esc_contact,
platform ? escaped(platform) : "");
+ tor_free(esc_contact);
}
if (msg)
*msg = "Rejected: There is already a verified server with this nickname "
@@ -449,10 +451,9 @@ authdir_wants_to_reject_router(routerinfo_t *ri, const char **msg,
if (ri->cache_info.published_on > now+ROUTER_ALLOW_SKEW) {
log_fn(severity, LD_DIRSERV, "Publication time for nickname '%s' is too "
"far (%d minutes) in the future; possible clock skew. Not adding "
- "(ContactInfo '%s', platform '%s').",
+ "(%s)",
ri->nickname, (int)((ri->cache_info.published_on-now)/60),
- ri->contact_info ? ri->contact_info : "",
- ri->platform ? ri->platform : "");
+ esc_router_info(ri));
*msg = "Rejected: Your clock is set too far in the future, or your "
"timezone is not correct.";
return -1;
@@ -460,11 +461,9 @@ authdir_wants_to_reject_router(routerinfo_t *ri, const char **msg,
if (ri->cache_info.published_on < now-ROUTER_MAX_AGE_TO_PUBLISH) {
log_fn(severity, LD_DIRSERV,
"Publication time for router with nickname '%s' is too far "
- "(%d minutes) in the past. Not adding (ContactInfo '%s', "
- "platform '%s').",
+ "(%d minutes) in the past. Not adding (%s)",
ri->nickname, (int)((now-ri->cache_info.published_on)/60),
- ri->contact_info ? ri->contact_info : "",
- ri->platform ? ri->platform : "");
+ esc_router_info(ri));
*msg = "Rejected: Server is expired, or your clock is too far in the past,"
" or your timezone is not correct.";
return -1;
@@ -472,10 +471,9 @@ authdir_wants_to_reject_router(routerinfo_t *ri, const char **msg,
if (dirserv_router_has_valid_address(ri) < 0) {
log_fn(severity, LD_DIRSERV,
"Router with nickname '%s' has invalid address '%s'. "
- "Not adding (ContactInfo '%s', platform '%s').",
+ "Not adding (%s).",
ri->nickname, ri->address,
- ri->contact_info ? ri->contact_info : "",
- ri->platform ? ri->platform : "");
+ esc_router_info(ri));
*msg = "Rejected: Address is not an IP, or IP is a private address.";
return -1;
}
diff --git a/src/or/or.h b/src/or/or.h
index 43f4fdbfd4..ccc0195ae4 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2362,6 +2362,7 @@ void networkstatus_list_update_recent(time_t now);
void router_reset_descriptor_download_failures(void);
void router_reset_status_download_failures(void);
int router_differences_are_cosmetic(routerinfo_t *r1, routerinfo_t *r2);
+const char *esc_router_info(routerinfo_t *router);
/********************************* routerparse.c ************************/
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 55a9f6a736..b4b35a5514 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -3792,3 +3792,25 @@ routerlist_assert_ok(routerlist_t *rl)
}
}
+const char *
+esc_router_info(routerinfo_t *router)
+{
+ static char *info;
+ char *esc_contact, *esc_platform;
+ size_t len;
+ if (info)
+ tor_free(info);
+
+ esc_contact = esc_for_log(router->contact_info);
+ esc_platform = esc_for_log(router->platform);
+
+ len = strlen(esc_contact)+strlen(esc_platform)+32;
+ info = tor_malloc(len);
+ tor_snprintf(info, len, "Contact %s, Platform %s", esc_contact,
+ esc_platform);
+ tor_free(esc_contact);
+ tor_free(esc_platform);
+
+ return info;
+}
+