The problem was the atoi() in fetch_from_buf_http: it's entirely too happy to read off the end of a buf if there is no subsequent '\n' in the same chunk as the "content-length".
We fixed this with the patch for #20384 (moved), where we made sure that every buf chunk was NUL-terminated, but we really ought to fix the underlying issue too.
I have an overcomplicated patch in bug20894_024. Probably it should use tor_parse_uint64 instead of atoi. But the part that I really dislike is the hunt-for-the-newline-and-copy-the-header part -- it's overcomplicated and more than a little bit zany.
Trac: Summary: Fix known instance of TROVE-2016-10-001 to Resolve read-off-end-of-buffer on atoi in fetch_from_buf_http (TROVE-2016-10-001)
My branch bug20894_024_v2 is now updated to use a separate function here, and to include a unit test. It's written a little bit oddly for backward compatibility with 0.2.4's compiler flags and coding style, but it's fairly clean. Please review?
Trac: Priority: Medium to High Status: assigned to needs_review
If so, we also need:
tor_assert(headers < SIZE_T_MAX - headerlen);
Before every time we do headers+headerlen.
(And before:
p = (char*) tor_memstr(headers, headerlen, CONTENT_LENGTH);
which effectively does headers+headerlen.)
Nickm tells me he's confident that the sentinel patch (already applied back through 0.2.4) has resolved the security issue. So this is just to clean up the code to make things better for our future? That sounds like a great thing to put into Tor 0.3.0 (like the body of this ticket suggests).
I believe it can't, since headers is a pointer to a place in a buffer, and headerlen is an amount of memory that's readable at that point.
I've forward-ported to 0.2.9, moved the unit test, added a correct use of STATIC, and credited AFL in a branch bug20894_029_v3. I'm fine taking this in 0.3.0 or 0.2.9.