Browse Source

Fix a fun bug that was probably causing unnecessary downloads, and that coupld possibly have caused some segfaults: When post-processing a split fingerprint URL, we were trying to base16_decode() entries already in the fingerprint list, failing, and removing them. Ow.

svn:r5326
Nick Mathewson 20 years ago
parent
commit
267af9ecf9
1 changed files with 7 additions and 2 deletions
  1. 7 2
      src/or/directory.c

+ 7 - 2
src/or/directory.c

@@ -1667,10 +1667,13 @@ dir_split_resource_into_fingerprints(const char *resource,
                                      smartlist_t *fp_out, int *compressed_out,
                                      int decode_hex)
 {
+  int old_len;
+  tor_assert(fp_out);
+  old_len = smartlist_len(fp_out);
   smartlist_split_string(fp_out, resource, "+", 0, 0);
   if (compressed_out)
     *compressed_out = 0;
-  if (smartlist_len(fp_out)) {
+  if (smartlist_len(fp_out) > old_len) {
     char *last = smartlist_get(fp_out,smartlist_len(fp_out)-1);
     size_t last_len = strlen(last);
     if (last_len > 2 && !strcmp(last+last_len-2, ".z")) {
@@ -1682,14 +1685,16 @@ dir_split_resource_into_fingerprints(const char *resource,
   if (decode_hex) {
     int i;
     char *cp, *d = NULL;
-    for (i = 0; i < smartlist_len(fp_out); ++i) {
+    for (i = old_len; i < smartlist_len(fp_out); ++i) {
       cp = smartlist_get(fp_out, i);
       if (strlen(cp) != HEX_DIGEST_LEN) {
+        info(LD_DIR, "Skipping digest \"%s\" with non-standard length.", cp);
         smartlist_del(fp_out, i--);
         goto again;
       }
       d = tor_malloc_zero(DIGEST_LEN);
       if (base16_decode(d, DIGEST_LEN, cp, HEX_DIGEST_LEN)<0) {
+        info(LD_DIR, "Skipping non-decodable digest \"%s\"", cp);
         smartlist_del(fp_out, i--);
         goto again;
       }