G
gert
free() is defined to do nothing, if you pass a null
pointer to it. The problem is because when you go
and write data to this null pointer, anything could
happen.
#include <fcgi_stdio.h>
#include <stdlib.h>
int post(){
char *input;
char *lenstr;
long len;
lenstr=getenv("CONTENT_LENGTH");
len=-1;
if (lenstr != NULL) sscanf(lenstr,"%ld",&len);
input = malloc(len+1);
if (input != NULL) fgets(input, len+1, stdin);
printf("Content-Type: text/xml; charset=utf-8"
"\r\n"
"\r\n"
"<xml>%s</xml>"
"\n",input);
free(input);
return 0;
}
int main (void){
while (FCGI_Accept() >= 0) { post(); }
return 0;
}
Changed the code a bit so it will always post back generated output no
matter what happens.
PS It doesn't look that more difficult compared to php or python