]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Stop logging stack contents when reading a zero-length bandwidth file
authorteor <teor2345@gmail.com>
Wed, 2 May 2018 12:33:21 +0000 (22:33 +1000)
committerjuga0 <juga@riseup.net>
Wed, 9 May 2018 15:19:28 +0000 (15:19 +0000)
When directory authorities read a zero-byte bandwidth file, they log
a warning with the contents of an uninitialised buffer. Log a warning
about the empty file instead.

Fixes bug 26007; bugfix on 0.2.2.1-alpha.

changes/bug26007 [new file with mode: 0644]
src/or/dirserv.c

diff --git a/changes/bug26007 b/changes/bug26007
new file mode 100644 (file)
index 0000000..efcd150
--- /dev/null
@@ -0,0 +1,5 @@
+  o Major bugfixes (directory authorities, security):
+    - When directory authorities read a zero-byte bandwidth file, they log
+      a warning with the contents of an uninitialised buffer. Log a warning
+      about the empty file instead.
+      Fixes bug 26007; bugfix on 0.2.2.1-alpha.
index 41c6bf3dc8d063d370986922fc36b262e27a3f3e..94290d5dd852bff6b47472498385aa03b984853a 100644 (file)
@@ -2750,14 +2750,23 @@ dirserv_read_measured_bandwidths(const char *from_file,
   time_t file_time, now;
   int ok;
 
+  /* Initialise line, so that we can't possibly run off the end. */
+  memset(line, 0, sizeof(line));
+
   if (fp == NULL) {
     log_warn(LD_CONFIG, "Can't open bandwidth file at configured location: %s",
              from_file);
     return -1;
   }
 
-  if (!fgets(line, sizeof(line), fp)
-          || !strlen(line) || line[strlen(line)-1] != '\n') {
+  /* If fgets fails, line is either unmodified, or indeterminate. */
+  if (!fgets(line, sizeof(line), fp)) {
+    log_warn(LD_DIRSERV, "Empty bandwidth file");
+    fclose(fp);
+    return -1;
+  }
+
+  if (!strlen(line) || line[strlen(line)-1] != '\n') {
     log_warn(LD_DIRSERV, "Long or truncated time in bandwidth file: %s",
              escaped(line));
     fclose(fp);