i been stuck with these 2 errors for days which i don't really know what causes them..tried debugging parse and as far as i can tell abs_path is working as it should(although i'm not sure it's written in the right way!)..here is my code for parse and lookup..thx in advance https://gist.github.com/cb99b7dffebbbd54b879ec7deaea28f1
Scope. Pointers. While debugging, if you are inspecting abs_path while in parse it may very well be right. Remember that main will use abs_path, so you need to inspect it there too, when you return from parse. That will tell a very different story. One problem is here
abs_path = realloc(abs_path, sizeof(LimitRequestLine + y)); abs_path = absl;
abs_path is allocated around line 183 in server thusly
char abs_path[LimitRequestLine + 1];. There it gets an address. When you realloc the local abs_path in parse, it will get a new address. (and then
abs_path = abs1 will give it still yet another new address). Alas, when you return to main, it will be looking at the original address. Think
strcpy. (And query too!)
Fixing this problem may provoke other problems. And this may not be the only problem. Keep at the debugging and you will have success.
On more careful review, I see that the
realloc is conditional. There's a serious problem with the condition, to wit
abs_path = realloc(abs_path, sizeof(LimitRequestLine + y)). LimitRequestLine + y will be an int, sizeof(int) is 8. It's a seg fault waiting to happen. You should not be testing that condition. Since
line is limited to LimitRequestLine bytes, and abs_path is a subset of line, it can never be bigger. If control ever reaches the
realloc, program will seg-fault. (which perhaps it did in your first iteration, since check50 gave
\ expected output, not an exit code of 0). Which also means you either got seg faults when you submitted a request from browser or curl OR you never sent a request to server. check50 step should come after you have a reasonable expectation that your program will pass. If you are getting seg faults, you should expect check50 to fail, so it is not ready to submit. If you have never even run server (and sent a request like cat.jpg or hello.html), it is definitely not ready to submit.