Re: int urldecode(char *src, char *last, char *dest)



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 ?

.



Relevant Pages

  • Re: Memory leaks help with char*
    ... I'm sure I've got some memory leaks here. ... I get an error when I try to delete my char* variables. ... pszFileName = strcat; ... //delete pfile; ...
    (microsoft.public.vc.language)
  • Re: int urldecode(char *src, char *last, char *dest)
    ... char *post{ ... fgets(input, len+1, stdin); ... IMPLEMENT LATER NEED SLEEP FIRST ... meaning safety code with no memory leaks or ...
    (comp.lang.c)
  • Re: a curious questions about return type
    ... Andrew Poelstra wrote: ... char month; ... in order to prevent memory leaks. ...
    (comp.lang.c)
  • IE6 Script Error
    ... The error has been occuring for some ... Char: 38 ... Other web pages are also showing minor errors; ... How does one determine what function is causing the problem and how does one ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Strange behaviour
    ... pass it a char. ... you cause a buffer overflow if byte has ... All the values that fit into uchar fit this criteria. ... Of course, in theory it is possible that this function will be passed bad data, and so precautions should be taken (in this case, simply using an unsigned char will eliminate all issues, because anything bigger than 255 will be wrapped). ...
    (comp.lang.c)