0

enter image description hereHere's my indexes function

char* indexes(const char* path)
{
    char* html = "index.html";
    char* php = "index.php";
    char* index = malloc(strlen(path) + strlen(html) + 1);
    strcpy(index,path);

    strcat(index,php);

    if(access(index,R_OK) != -1){
        return index;
    }
    strcpy(index,path);

    strcat(index,html);
    if(access(index,R_OK) != -1){
        return index;
    }
    else{
        return NULL;   
    }
}

Here's my snippet of parse funcion

 //storing the query
    if(strchr(line,63) != 0){   //63 is the ascii value of ?
        temp = (strchr(line,'?') + 1);
        strcpy(query,temp);
        query[strlen(query)-strlen(http_ver) - 3] = '\0';
    }
    else{
        strcpy(query,"");
    }
    //request method
  //  char request[80];
  //  char absolute[80];
    temp = strchr(line,47);
    char* request = malloc(sizeof(temp));
    char* absolute = malloc(sizeof(temp));

    strcpy(request,temp);
    request[strlen(request)-strlen(http_ver) - 3] = '\0';
    if(strcmp(query,"") == 0){
        strcpy(absolute,temp);
        absolute[strlen(absolute)-strlen(http_ver) - 3] = '\0';
    }
    else{
        strcpy(absolute,request);
        absolute[strlen(absolute)-strlen(query)-1] = '\0';
    }
    strcpy(abs_path,absolute);
   // char* query_ex = malloc(sizeof(query));
    if(query == 0 || (strcmp(query,"?") == 0)){
        strcpy(query,"");
    }
    return true;

enter image description here

0
1

There's a couple of problems. debug50 and gdb would be very helpful in troubleshooting and debugging server.

The backtrace errors are seg faults that are coming from the indexes function.

This temp = strchr(line,((char)63)+1); looks like a problem. It is asking strchr to find '@' (ascii 64) in line. Since it doesn't find '@', temp is NULL and program gives a segfault at strcpy(query,temp); You are likely looking for the location of the '?' +1, in which case you need to adjust the parentheses. As a point of clarity, it is unnecessary to cast 63. The code would be simpler and clearer with strchr(line,'?').

Addendum This sizeof(path) is probably the problem with indexes function. You didn't mean sizeof.

gdb indicates that abs_path is wrong when there is a query. Review the spec:

Per 5.3 of the same RFC, request-target, meanwhile, can take several forms, the only one of which your server needs to support is

absolute-path [ "?" query ]

whereby absolute-path (which will not contain ?) must start with / and might optionally be followed by a ? followed by a query, which may not contain ".

absolute-path should not include the '?' nor the query itself.

4
  • Thank you so much. Solved all except one! couldn't find the error for that one!
    – azmain
    Dec 14 '16 at 23:51
  • Suggest you take that exact request ("hello.php") through gdb. Make sure to inspect abs_path and query when control returns to main. Dec 15 '16 at 12:59
  • Solved. Thanks so much. Added a bit line of code.if(strchr(absolute,63) != 0){ int n = strlen(absolute); absolute[n-1] = '\0'; }
    – azmain
    Dec 15 '16 at 15:49
  • Glad to help. And remember how we say Thanks! on StackExchange. Dec 15 '16 at 17:45

You must log in to answer this question.

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