Commit 4d3e709c authored by Nick Mathewson's avatar Nick Mathewson 🦀
Browse files

Use escaped() for remaining cases.


svn:r6117
parent 86a72f73
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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.
+4 −0
Original line number Diff line number Diff line
@@ -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 '\\':
+9 −11
Original line number Diff line number Diff line
@@ -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;
  }
+1 −0
Original line number Diff line number Diff line
@@ -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 ************************/

+22 −0
Original line number Diff line number Diff line
@@ -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;
}