Browse Source

r11927@catbus: nickm | 2007-02-24 14:49:31 -0500
Make sure every error case of router_dump_router_to_string warns about what actually went wrong.


svn:r9642

Nick Mathewson 18 years ago
parent
commit
501659e67c
1 changed files with 20 additions and 7 deletions
  1. 20 7
      src/or/router.c

+ 20 - 7
src/or/router.c

@@ -1242,16 +1242,20 @@ router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
   tor_free(identity_pkey);
   tor_free(identity_pkey);
   tor_free(bandwidth_usage);
   tor_free(bandwidth_usage);
 
 
-  if (result < 0)
+  if (result < 0) {
+    log_warn(LD_BUG,"descriptor snprintf #1 ran out of room!");
     return -1;
     return -1;
+  }
   /* From now on, we use 'written' to remember the current length of 's'. */
   /* From now on, we use 'written' to remember the current length of 's'. */
   written = result;
   written = result;
 
 
   if (options->ContactInfo && strlen(options->ContactInfo)) {
   if (options->ContactInfo && strlen(options->ContactInfo)) {
     result = tor_snprintf(s+written,maxlen-written, "contact %s\n",
     result = tor_snprintf(s+written,maxlen-written, "contact %s\n",
                           options->ContactInfo);
                           options->ContactInfo);
-    if (result<0)
+    if (result<0) {
+      log_warn(LD_BUG,"descriptor snprintf #2 ran out of room!");
       return -1;
       return -1;
+    }
     written += result;
     written += result;
   }
   }
 
 
@@ -1265,24 +1269,31 @@ router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
   }
   }
   for ( ; tmpe; tmpe=tmpe->next) {
   for ( ; tmpe; tmpe=tmpe->next) {
     result = policy_write_item(s+written, maxlen-written, tmpe);
     result = policy_write_item(s+written, maxlen-written, tmpe);
-    if (result < 0)
+    if (result < 0) {
+      log_warn(LD_BUG,"descriptor policy_write_item ran out of room!");
       return -1;
       return -1;
+    }
     tor_assert(result == (int)strlen(s+written));
     tor_assert(result == (int)strlen(s+written));
     written += result;
     written += result;
-    if (written+2 > maxlen)
+    if (written+2 > maxlen) {
+      log_warn(LD_BUG,"descriptor policy_write_item ran out of room (2)!");
       return -1;
       return -1;
+    }
     s[written++] = '\n';
     s[written++] = '\n';
   }
   }
 
 
-  if (written+256 > maxlen) /* Not enough room for signature. */
+  if (written+256 > maxlen) { /* Not enough room for signature. */
+    log_warn(LD_BUG,"not enough room left in descriptor for signature!");
     return -1;
     return -1;
+  }
 
 
   /* Sign the directory */
   /* Sign the directory */
   strlcpy(s+written, "router-signature\n", maxlen-written);
   strlcpy(s+written, "router-signature\n", maxlen-written);
   written += strlen(s+written);
   written += strlen(s+written);
   s[written] = '\0';
   s[written] = '\0';
-  if (router_get_router_hash(s, digest) < 0)
+  if (router_get_router_hash(s, digest) < 0) {
     return -1;
     return -1;
+  }
 
 
   note_crypto_pk_op(SIGN_RTR);
   note_crypto_pk_op(SIGN_RTR);
   if (router_append_dirobj_signature(s+written,maxlen-written,
   if (router_append_dirobj_signature(s+written,maxlen-written,
@@ -1292,8 +1303,10 @@ router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
   }
   }
   written += strlen(s+written);
   written += strlen(s+written);
 
 
-  if (written+2 > maxlen)
+  if (written+2 > maxlen) {
+    log_warn(LD_BUG,"Not enough room to finish descriptor.");
     return -1;
     return -1;
+  }
   /* include a last '\n' */
   /* include a last '\n' */
   s[written] = '\n';
   s[written] = '\n';
   s[written+1] = 0;
   s[written+1] = 0;