summaryrefslogtreecommitdiff
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
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
-rw-r--r--ChangeLog6
-rw-r--r--src/common/compat.c7
2 files changed, 11 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index a08ea9ae7e..159a8a5092 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,10 +7,12 @@ Changes in version 0.1.2.4-alpha - 2006-11-??
don't recognize; it's probably just from a newer version of Tor.
- Have directory authorities allow larger amounts of drift in uptime
without replacing the server descriptor: previously, a server that
- restarted every 30 minutes could have 48 "interesting" descriptors per
- day.
+ restarted every 30 minutes could have 48 "interesting" descriptors
+ per day.
- Start linking to the Tor specification and Tor reference manual
correctly in the Windows installer.
+ - Avoid assert failure when our cached-routers file is empty on
+ startup.
Changes in version 0.1.2.3-alpha - 2006-10-29
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);