0

Running my first function through check 50 everything goes fine except the last check for two spaces before http. Instead of giving me an error code the program exits with "error backtrace" whatever that is.

bool parse(const char* line, char* abs_path, char* query)
{
    //make sure method request is get
  const char* get = "GET /";
  if (strncmp(get, line, 4) != 0)
   {
    error(405);
    return false;
   }
   //make sure request Target begins with slas

  if (strncmp(get, line, 5) != 0)
   {
    error(501);
    return false;
   }
    if (strchr( line, '"') > 0)
   {
    error(400);
    return false;
   }

  if (strncmp(strrchr (line, ' '), " HTTP/1.1\r\n", 9) != 0)
   {
           error(505);
    return false;
   }
    //separate requests Target
    char rt [LimitRequestLine + 1];// rt +  =  NULL;
    strcpy (rt, (strchr (line, ' ')));
    //get absolute path path
    char abspath [LimitRequestLine + 1];//
    strcpy (abspath, (strchr (line, '/')));
    //get absolute path p
    int apc = 0;
   while ( abspath[apc] != ' ' && abspath[apc] != '?' )
          apc++;
    strncpy(abs_path, abspath, apc);

    char que [LimitRequestLine + 1];//    // get query
    if (strchr (line, '?') == NULL)
    {
        que[0] = '\0';
        strcpy (query, que);
    }
    else
    {
        strcpy (que, (strchr (line, '?')));

             //get absolute path p = NULL;
        int qc = 0;
        while ( que[qc] != ' '  )
            qc++;
        strncpy(query, que, qc);
    }

   return true;
}
0

If memory servers, a backtrace error from check50 indicates a seg fault. This function will not detect two spaces before HTTP, since strrchr detects the last occurrence of char(therefore the "second" space is before the "last" space). So what's happening? I would say, after a cursory read, that abs_path and query are not null terminated. Plus there are ambiguous while loops because there are no {} around the bodies.

You must log in to answer this question.

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