tor segfaults on 64k-aligned cached-routers file
This bug is for svn and the 0.1.2.x tree, which are both affected.
When Tor gets to the end of an 4k-aligned file (page size?), it segfaults in eat_whitespace()
The problem is imminent at routerparse.c:899 when both end and eos are out of bounds. (eos is (always?) out of bounds when the mmap is page-aligned.) Execution then enters router_parse_entry_from_string(), which calls tokenize_string(s, end...) with end out of bounds. That calls eat_whitespace, which is not safe for non-null-terminated strings (as it has no end pointer or length specifier).
Steps to reproduce:
- minimal torrc with RunAsDaemon 0, DataDirectory /some/path/ which points to...
- A valid 4096-byte (I've only tested with 2!^x * 4096-byte files) cached-routers file (below, or take an existing cached-routers file and chop it, then duplicate/remove/modify exit policy entries until you get to an appropriate size)
I've collected sample cached-routers files of the obvious sizes that seems to trigger the bug on both my x86 and x86-64 machines. http://126.96.36.199/svn/cr/
The crashes I get are in eat_whitespace(), but the original reporter on IRC was seeing segfaults in 0.1.2.14, routerparse.c:679 -- on PPC. A representative backtrace from his PPC is at http://www.pastebin.ca/608408 One with a segfault in eat_whitespace (on x86-64) is at http://www.pastebin.ca/608454
[Automatically added by flyspray2trac: Operating System: All]