aboutsummaryrefslogtreecommitdiff
path: root/src/common/storagedir.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-03-27 10:40:15 +0200
committerNick Mathewson <nickm@torproject.org>2017-03-27 10:40:15 +0200
commit1d617e3ed0a6c380d1bde9654a518c8a83d21db3 (patch)
tree41dd7590f45719281e853eafc844048c06e5b57d /src/common/storagedir.c
parent0895808023b023a8eff00c6b6eb27c4ec4b40191 (diff)
downloadtor-1d617e3ed0a6c380d1bde9654a518c8a83d21db3.tar.gz
tor-1d617e3ed0a6c380d1bde9654a518c8a83d21db3.zip
Check and cast st_size to size_t in storagedir code
This prevents an i386 compilation warning and fixes bug 21828. Bug not in any released Tor.
Diffstat (limited to 'src/common/storagedir.c')
-rw-r--r--src/common/storagedir.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/common/storagedir.c b/src/common/storagedir.c
index b7d43ddf13..e28a66f693 100644
--- a/src/common/storagedir.c
+++ b/src/common/storagedir.c
@@ -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;