embedthis/goahead — Issue #1: h.c assumes void* equals int size. Not true on 64 bit platforms
Author: neilsone
Created: 2012-02-13 20:29:52+00:00
State: open

Overview: I discovered 64-bit builds on MACOSX would compile and run but upon serving up a page, the page entire page would not get served up and the WebServer would crash. I narrowed the problem down to the functions within h.c. While I didn't narrow in on the absolute root cause, the problem appears to be due to the invalid assumption that void* equals int in size for some of the size/offset calculations done within h.c. When compiling WebServer 2.5 on MACOSX, specifically Lion, MACOSX defaulted to 64-bit builds. Setting the -m32 CFLAG on MACOSX will force a 32 bit build and effectively works around this problem.

Steps to Reproduce:
1. Build a 64-bit WebServer on MACOSX (although any 64-bit build should reproduce this since the h.c code is not OS specific)
2. Run WebServer in test mode. Connect with a browser and request the wwwdemo/home.htm page. (Just an example, pretty much any page of a certain length will cause the error).

Observed Results
1. Analyzing the returned code served by the WebServer, the entire html page is not returned to the requesting browser (the request never completes)
2. The WebServer segfaults on exit or randomly if enough pages are requested.

Expected Results
1. No crash on exit and html pages served up in full as long as length is within supported parameters

Troubleshooting Performed
1. Stepped through with gdb and narrowed down source of errors to entries in handle lists. Offsets were incorrect and improperly reached the end of the list resulting in failure to serve up full requests. Incorrect pointers offsets also led to accessing invalid data. Quick code inspection of h.c shows assumptions that int and void* are of equal size which is an invalid assumption on 64-bit platforms.

Workarounds
1. Set the -m32 CFLAG on MACOSX or similar flags on other platforms to force a 32-bit build. This is not a suitable workaround if a 64-bit build is required.