Working on server.c pset6.I get HTTP/1.1 403 Forbidden while I run server.c. I used gdb and found a flaw in indexes().I used printf statements and figured out that after I use strcpy function the path changes from /home/Ubuntu/workspace/public to lic/ which eventually results in indexes returning NULL and giving 403 error. If someone could help explain that why is this the case. Posting my indexes code
char* indexes(const char* path)
{
char* returnString1=0;
char* Inphp="index.php";
char* Inhtml="index.html";
returnString1=calloc(1,sizeof(strlen(path)+strlen(Inphp)+1));
printf("PATh is %s\n",path);
//copy path to returnString1;
//add '\0' at the end of returnString1;
printf("PATh is %s\n",path);
// concatenate Inphp to returnString1;
printf("PATh is %s\n",path);
printf("ReturnString 1 is %s \n",returnString1);
char* returnString2=0;
returnString2=calloc(1,sizeof(strlen(path)+strlen(Inhtml)+1));
//add '\0' at the end of returnString2;
printf("PATh is %s\n",path);
//copy path to returnString2;
printf("PATh is %s\n",path);
printf("\nReturnString 2 is %s \n",returnString2);
// concatenate Inhtml to returnString2;
printf("ReturnString 2 is %s \n",returnString2);
if(access(returnString1,F_OK)==1)
{ //free returnString2;
return returnString1;
}
else if(access(returnString2,F_OK)==1)
{
// free returnString1
return returnString2;
}
return NULL;
}
Posting the gdb output picture![GDB SCREENSHOT PATH ]1