Re: int urldecode(char *src, char *last, char *dest)
- From: "gert" <gert.cuykens@xxxxxxxxx>
- Date: 15 Feb 2007 10:18:08 -0800
On Feb 15, 1:49 am, "Old Wolf" <oldw...@xxxxxxxxxxxxxx> wrote:
On Feb 13, 12:31 pm, "gert" <gert.cuyk...@xxxxxxxxx> wrote:
This based on a example i found athttp://www.cs.tut.fi/~jkorpela/
forms/cgic.html
I looked at this code, it is dreadful and I advise you to not take
it as gospel. As well as causing a buffer overflow if the text
ends in "%" or "%x", it causes a buffer overflow if the text is
shorter than 5 characters. Also it contains this gem:
printf("%s%c%c\n", "STUFF",13,10);
This is entirely equivalent to:
printf("%s\r\n\n", "STUFF");
(unless the compiling machine is not ASCII, in which case, it's
hard to foresee how the target will handle the \n anyway).
Amusingly, the author wrote:
"CGI programming in C is clumsy and error-prone."
It certainly is, if he is the one doing the writing!
Made some changes to it :)
#include <fcgi_stdio.h>
#include <stdlib.h>
char *post(void){
char *input;
char *lenstr;
long len;
lenstr=getenv("CONTENT_LENGTH");
if (lenstr != NULL && sscanf(lenstr,"%ld",&len)==1 ) {
input = malloc(len+1);
fgets(input, len+1, stdin);
//urldecode(); IMPLEMENT LATER NEED SLEEP FIRST
printf("Content-Type: text/xml; charset=utf-8"
"\r\n"
"\r\n"
"<xml>%s %d</xml>"
"\n"
,input,len);
free(input);
}
return 0;
}
int main (void){
char * input;
while (FCGI_Accept() >= 0) {
post();
}
return 0;
}
Is this Wolf approved, meaning safety code with no memory leaks or
other memory violations ?
.
- Follow-Ups:
- Re: int urldecode(char *src, char *last, char *dest)
- From: Old Wolf
- Re: int urldecode(char *src, char *last, char *dest)
- References:
- int urldecode(char *src, char *last, char *dest)
- From: gert
- Re: int urldecode(char *src, char *last, char *dest)
- From: Old Wolf
- int urldecode(char *src, char *last, char *dest)
- Prev by Date: OT - (was: Re: OT: Google's latest dungheap)
- Next by Date: Re: Automatically generate variables
- Previous by thread: Re: int urldecode(char *src, char *last, char *dest)
- Next by thread: Re: int urldecode(char *src, char *last, char *dest)
- Index(es):
Relevant Pages
|