deplinenoise/webby — pull request #5 by hulkholden (2013-03-24 00:20:45+00:00)
Title: Fix for a nasty memory corruption bug

I found a 100% repeatable crash after serving a page with many links. With the same config as the demo.c, reading data into connection[0]->header_buf would corrupt connection[3]. If requests come in slowly enough, the corruption wouldn't cause any problems. But if 4 connections cam in simultaneously, it would trigger a crash one of the FD_ISSET calls just prior to calling wb_update_client().

I tracked it down to the way that WebbyServerInit was reserving memory for all of the connections. It was initialising connection_max connections, but only reserving/allocating memory for connection_max-1 connections.

I also split up the initial buffer increment so that there's two calls to WB_ALIGN_ARB, just like in WebbyServerMemoryNeeded. It's probably not an issue, but potentially align(a+b, 16) != align(a,16) + align(b,16), so it seemed safter just to keep them the same.