I'm working my way through the web server and am getting behavior I don't understand. I am consistently receiving a 500 error whatever I try to load in Chrome. I've added printf's (yes, I'm one of those) to output certain variables as I try loading different pages.
The first go through, all seems to look good - no odd characters being displayed - but then I get the 500 error. It then tries to get /favicon.ico and my variables begin displaying bizarre content.
For instance, my request_target is sized to be the number of bytes between the spaces in (i.e., line variable)
char request_target[strrchr(line, ' ') - strchr(line, ' ')]
but when I the value of request_target is displayed as (the value is actually changing each time, this is just the latest run).
I am building request_target as follows:
strncpy(request_target, (strchr(line, ' ') + 1), (strrchr(line, ' ') - strchr(line, ' '));
I get similar behavior in my absolute_path and concatenated path variables because the junk in request_target appears to be carried over.
What fundamental error have I made but missed?