Thread: little help here needed.

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    10

    little help here needed.

    hey community!

    i've been developing this fastcgi app to run ontop of nginx. and so far i've been doing good (while writing a parser for GET requests), so i moved on to implementing a POST request parser (which is essentially the same as the GET one), got it into local variables.. and everything seems fine, except the fact that in the constant (fcgi_accept loop) my parser will only eat ANY (get/post) request ONLY ONCE - and after that terminates with a segfault.

    now in order to parse the request i use strtok() function and basic strcmp() stuff from <string.h>

    prototype of a request is name/value pair such as mine "method=name_of_it"

    question is: has anyone ever encountered such kind of error, if you did (or did not) any ideas why this might be happening?!

    btw, before integrating the POST request handler (two lines of code), everything seemed to work fine and the constant accept loop persisted its existence until "method=kill" was passed through!

    any help would be appreciated!!

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Don't know if this will help you or not, but did you account for the fact that strtok() will write data into the string it is working on (NULL char's)?

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    10
    after running gdb found out that i get a segfault in strcmp() for some reason :/
    right after commenting out all strcmp() cases - my program seems to work, but i'd like to use built-in functions, instead of writing my own or using non-native libraries..
    @Adak yeah i know that strtok() can sometimes be somewhat dangerous, but i think its the only feasible solution i have ://

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Are you passing strcmp() two pointers to strings that are properly terminated?

    If so, then I'd re-think that "coincidence" that strtok() tears apart strings, and now strcmp(), which works on strings, is crashing.

    You can always work at the char level and leave your original string unchanged. More than one way to skin ye old cat.

  5. #5
    Registered User
    Join Date
    Oct 2011
    Posts
    10
    trying to find the quickest one
    i want to move on with this stuff
    anyways, i'll probably go with the old way - char-by-char... oh well
    thanks on that mate!
    cheers

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Without the code, I don't understand how you expect us to help you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help needed
    By golf in forum C Programming
    Replies: 1
    Last Post: 04-07-2008, 09:46 PM
  2. a little help needed
    By dopecat in forum C++ Programming
    Replies: 5
    Last Post: 04-10-2007, 10:10 AM
  3. Help Needed !!
    By vodlum in forum C++ Programming
    Replies: 3
    Last Post: 10-03-2005, 02:33 PM
  4. Help needed.
    By hyrule in forum C++ Programming
    Replies: 2
    Last Post: 09-26-2005, 09:51 AM
  5. Help Needed Please!!!!!
    By jon_morrow in forum C++ Programming
    Replies: 7
    Last Post: 03-22-2002, 11:55 AM