]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Make all consumers of microdesc_t.body tolerate NULL
authorNick Mathewson <nickm@torproject.org>
Wed, 12 Jun 2013 16:12:11 +0000 (12:12 -0400)
committerNick Mathewson <nickm@torproject.org>
Wed, 12 Jun 2013 16:12:11 +0000 (12:12 -0400)
This is another fix to try to mitigate recurrences of 8031/8822.

src/or/control.c
src/or/dirserv.c
src/or/microdesc.c

index 48782682c77cf88c1f6a1211f7578b6feaa913dd..5ae7b71b5d29469862c3efcb9ad764f763dfb1bc 100644 (file)
@@ -1711,8 +1711,7 @@ getinfo_helper_dir(control_connection_t *control_conn,
     const node_t *node = node_get_by_hex_id(question+strlen("md/id/"));
     const microdesc_t *md = NULL;
     if (node) md = node->md;
-    if (md) {
-      tor_assert(md->body);
+    if (md && md->body) {
       *answer = tor_strndup(md->body, md->bodylen);
     }
   } else if (!strcmpstart(question, "md/name/")) {
@@ -1722,8 +1721,7 @@ getinfo_helper_dir(control_connection_t *control_conn,
     /* XXXX duplicated code */
     const microdesc_t *md = NULL;
     if (node) md = node->md;
-    if (md) {
-      tor_assert(md->body);
+    if (md && md->body) {
       *answer = tor_strndup(md->body, md->bodylen);
     }
   } else if (!strcmpstart(question, "desc-annotations/id/")) {
index 8f6d9ec43860dfb64add084501799769880506cc..3e46153a55df19439eb7eb1eef81eade79ffb797 100644 (file)
@@ -3981,7 +3981,7 @@ connection_dirserv_add_microdescs_to_outbuf(dir_connection_t *conn)
     char *fp256 = smartlist_pop_last(conn->fingerprint_stack);
     microdesc_t *md = microdesc_cache_lookup_by_digest256(cache, fp256);
     tor_free(fp256);
-    if (!md)
+    if (!md || !md->body)
       continue;
     if (conn->zlib_state) {
       /* XXXX024 This 'last' business should actually happen on the last
index f99e1c88adaf21d19d69da604c4ccbb317615df7..05e3b41815eebfb6ba3aa0fbb8b660dd488aae2b 100644 (file)
@@ -75,6 +75,10 @@ dump_microdescriptor(int fd, microdesc_t *md, size_t *annotation_len_out)
 {
   ssize_t r = 0;
   size_t written;
+  if (md->body == NULL) {
+    *annotation_len_out = 0;
+    return 0;
+  }
   /* XXXX drops unknown annotations. */
   if (md->last_listed) {
     char buf[ISO_TIME_LEN+1];
@@ -447,7 +451,7 @@ microdesc_cache_rebuild(microdesc_cache_t *cache, int force)
   HT_FOREACH(mdp, microdesc_map, &cache->map) {
     microdesc_t *md = *mdp;
     size_t annotation_len;
-    if (md->no_save)
+    if (md->no_save || !md->body)
       continue;
 
     size = dump_microdescriptor(fd, md, &annotation_len);