]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Recover better from empty/invalid storagedir files
authorNick Mathewson <nickm@torproject.org>
Mon, 20 Nov 2017 15:14:41 +0000 (10:14 -0500)
committerNick Mathewson <nickm@torproject.org>
Mon, 20 Nov 2017 15:14:41 +0000 (10:14 -0500)
If we can't read a file because of an FS issue, we say "we can't
read that" and move on.  But if we can't read it because it's empty,
because it has no labels, or because its labels are misformatted, we
should remove it.

Fixes bug 24099; bugfix on 0.3.1.1-alpha.

changes/bug24099 [new file with mode: 0644]
src/or/conscache.c

diff --git a/changes/bug24099 b/changes/bug24099
new file mode 100644 (file)
index 0000000..dca3992
--- /dev/null
@@ -0,0 +1,4 @@
+  o Minor bugfixes (directory cache):
+    - Recover better from empty or corrupt files in the consensus cache
+      directory. Fixes bug 24099; bugfix on 0.3.1.1-alpha.
+
index 9e13ce8e43d43fb714ae622279cd6fd3987284e6..4919dba3d2286688b92614358302d02f7045a53e 100644 (file)
@@ -539,9 +539,16 @@ consensus_cache_rescan(consensus_cache_t *cache)
     map = storage_dir_map_labeled(cache->dir, fname,
                                   &labels, &body, &bodylen);
     if (! map) {
-      /* Can't load this; continue */
-      log_warn(LD_FS, "Unable to map file %s from consensus cache: %s",
-               escaped(fname), strerror(errno));
+      if (errno == ERANGE || errno == EINVAL) {
+        log_warn(LD_FS, "Found %s file %s in consensus cache; removing it.",
+                 errno == ERANGE ? "empty" : "misformatted",
+                 escaped(fname));
+        storage_dir_remove_file(cache->dir, fname);
+      } else {
+        /* Can't load this; continue */
+        log_warn(LD_FS, "Unable to map file %s from consensus cache: %s",
+                 escaped(fname), strerror(errno));
+      }
       continue;
     }
     consensus_cache_entry_t *ent =