[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Try to fix warnings when size_t is smaller than st.st_size.
commit c3b720fb26cbe0ff5f53407ba4929b3bd75256b1
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Thu Jun 30 14:20:04 2016 -0400
Try to fix warnings when size_t is smaller than st.st_size.
---
src/or/routerparse.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index 875bb60..13ffaf9 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -886,11 +886,28 @@ dump_desc_populate_one_file, (const char *dirname, const char *f))
goto done;
}
+#if SIZE_MAX > UINT64_MAX
+ if (BUG((uint64_t)st.st_size > (uint64_t)SIZE_MAX)) {
+ /* LCOV_EXCL_START
+ * Should be impossible since RFTS above should have failed to read the
+ * huge file into RAM. */
+ goto done;
+ /* LCOV_EXCL_STOP */
+ }
+#endif
+ if (BUG(st.st_size < 0)) {
+ /* LCOV_EXCL_START
+ * Should be impossible, since the OS isn't supposed to be b0rken. */
+ goto done;
+ /* LCOV_EXCL_STOP */
+ }
+ /* (Now we can be sure that st.st_size is safe to cast to a size_t.) */
+
/*
* We got one; now compute its digest and check that it matches the
* filename.
*/
- if (crypto_digest256((char *)content_digest, desc, st.st_size,
+ if (crypto_digest256((char *)content_digest, desc, (size_t) st.st_size,
DIGEST_SHA256) != 0) {
/* Weird, but okay */
log_info(LD_DIR,
@@ -916,7 +933,7 @@ dump_desc_populate_one_file, (const char *dirname, const char *f))
ent = tor_malloc_zero(sizeof(dumped_desc_t));
ent->filename = path;
memcpy(ent->digest_sha256, digest, DIGEST256_LEN);
- ent->len = st.st_size;
+ ent->len = (size_t) st.st_size;
ent->when = st.st_mtime;
/* Null out path so we don't free it out from under ent */
path = NULL;
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits