]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Check and cast st_size to size_t in storagedir code
authorNick Mathewson <nickm@torproject.org>
Mon, 27 Mar 2017 08:40:15 +0000 (10:40 +0200)
committerNick Mathewson <nickm@torproject.org>
Mon, 27 Mar 2017 08:40:15 +0000 (10:40 +0200)
This prevents an i386 compilation warning and fixes bug 21828. Bug not
in any released Tor.

src/common/storagedir.c

index b7d43ddf13b6cc4048928681bf0c760307e9d248..e28a66f693545640f71f6195391e96fb78012f91 100644 (file)
@@ -205,8 +205,11 @@ storage_dir_read(storage_dir_t *d, const char *fname, int bin, size_t *sz_out)
   tor_asprintf(&path, "%s/%s", d->directory, fname);
   struct stat st;
   char *contents = read_file_to_str(path, flags, &st);
-  if (contents && sz_out)
-    *sz_out = st.st_size;
+  if (contents && sz_out) {
+    // it fits in RAM, so we know its size is less than SIZE_MAX
+    tor_assert((uint64_t)st.st_size <= SIZE_MAX);
+    *sz_out = (size_t) st.st_size;
+  }
 
   tor_free(path);
   return (uint8_t *) contents;