summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2006-11-12 07:09:22 +0000
committerRoger Dingledine <arma@torproject.org>2006-11-12 07:09:22 +0000
commit3d6b97399f335636eb3391b78a729f6219e16213 (patch)
tree680ba358d6e798e93ce18e2b5b8c77e9d05d42f3 /src/common
parent968b07985ee1091a44ff9f6299f383314660fe83 (diff)
downloadtor-3d6b97399f335636eb3391b78a729f6219e16213.tar.gz
tor-3d6b97399f335636eb3391b78a729f6219e16213.zip
Avoid assert failure when our cached-routers file is empty on startup.
(reported by revstray) svn:r8928
Diffstat (limited to 'src/common')
-rw-r--r--src/common/compat.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index e07d3a3695..db38e757e3 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -141,6 +141,13 @@ tor_mmap_file(const char *filename)
page_size = getpagesize();
size += (size%page_size) ? page_size-(size%page_size) : 0;
+ if (!size) {
+ /* zero-length file. if we call mmap on it, we'll end up setting
+ * data to NULL below, and bad things will happen. So just fail. */
+ log_notice(LD_FS,"File \"%s\" is empty. Ignoring.",filename);
+ return NULL;
+ }
+
string = mmap(0, size, PROT_READ, MAP_PRIVATE, fd, 0);
if (string == MAP_FAILED) {
close(fd);