[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] [tor/master 2/3] Add a more verbose log message to try to catch bug #2022.



Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Thu, 7 Oct 2010 16:04:24 -0400
Subject: Add a more verbose log message to try to catch bug #2022.
Commit: ab5b11fbb832cd51068060dfedc47d2a9c9f0622

---
 src/or/microdesc.c |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/src/or/microdesc.c b/src/or/microdesc.c
index 97d30ff..6d7a61f 100644
--- a/src/or/microdesc.c
+++ b/src/or/microdesc.c
@@ -416,7 +416,21 @@ microdesc_cache_rebuild(microdesc_cache_t *cache)
   SMARTLIST_FOREACH_BEGIN(wrote, microdesc_t *, md) {
     tor_assert(md->saved_location == SAVED_IN_CACHE);
     md->body = (char*)cache->cache_content->data + md->off;
-    tor_assert(!memcmp(md->body, "onion-key", 9));
+    if (PREDICT_UNLIKELY(
+                 md->bodylen < 9 || memcmp(md->body, "onion-key", 9) != 0)) {
+      /* XXXX023 once bug 2022 is solved, we can kill this block and turn it
+       * into just the tor_assert(!memcmp) */
+      off_t avail = cache->cache_content->size - md->off;
+      char *bad_str;
+      tor_assert(avail >= 0);
+      bad_str = tor_strndup(md->body, MIN(128, (size_t)avail));
+      log_err(LD_BUG, "After rebuilding microdesc cache, offsets seem wrong. "
+              " At offset %d, I expected to find a microdescriptor starting "
+              " with \"onion-key\".  Instead I got %s.",
+              (int)md->off, escaped(bad_str));
+      tor_free(bad_str);
+      tor_assert(!memcmp(md->body, "onion-key", 9));
+    }
   } SMARTLIST_FOREACH_END(md);
 
   smartlist_free(wrote);
-- 
1.7.1