1

I have implemented server up to the point of respond to client. When I make a request for static content from Chrome, I get this:

GET /cat.html HTTP/1.1
THE QUERY IS 
THE ABSOLUTE PATH IS /cat.html
THE PATH IS /home/jharvard/Dropbox/pset6/public/cat.html
THE EXTENSION SIZE IS 5
THE EXTENSION IS html
HTTP/1.1 200 OK
GET /cat.html HTTP/1.1
HTTP/1.1 400 Bad Request
THE QUERY IS
Segmentation fault (core dumped)

GDB:

Program received signal SIGSEGV, Segmentation fault.
0x08049719 in main (argc=4, argv=0xbffff194) at server.c:332
warning: Source file is more recent than executable.
332             
printf("THE PATH IS %s\n", path);

The first loop works great but then it loops again without truly resetting everything, I think. Why does it work the first time and then repeat? Is it because I have not implemented the last piece of the pset?

int lineLength = strlen(line);
int spaces = 0;

char* requestStart = NULL; // position after first ' '
char* httpVersionStart = NULL; // position after second ' '
char* queryStart = NULL; // position after (?)

bool validReqTargetPath;
bool validReqTargetFile;
bool validReqTargetString = true;

[code is hidden behind the edit flag so it remains out of view of casual viewers of the page]

1
  • gdb warns you that your source code file is more recent than the executable. that means that you updated your source code and forgot to compile. re-compile your code and try again with gdb. notice that it tells you the line number of cause of the segfault. that should give some clues.
    – kzidane
    Aug 14 '15 at 8:02
2

Because you didn't initialise your first two booleans:

bool validReqTargetPath;
bool validReqTargetFile;

when you refresh the page, it is likely that you will be given the same memory on the stack as you were given the first time through the loop... as such, the values may be bogus.

Initialise those values and the segfault will be solved.

2
  • Thank you so much for the help! Aug 14 '15 at 8:32
  • Thanks for helping him kiwi! +1
    – i_am_david
    Aug 14 '15 at 17:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .