[En-Nut-Discussion] Saving application settings does not work

Harald Kipp harald.kipp at egnite.de
Mon Jan 16 21:15:20 CET 2006


No idea wether this also refers to

Subject: "Need Help with REQUEST structure - Query StringParsing."

But one thing is definitely wrong:

char *p;

p = NutHttpGetParameter();

Now p points to a dynamic storage area. If the code in
pro/httpd decides to destroy this string, p will point
to an invalid area.

p = "somevalue";

Here p points to a static string reserved by the compiler,
which will never disappear and p will always point to it.

Possible solution:

char *p; // Global, automatically NULL after start.

char *pt; // Local variable.

pt = NutHttpGetParameter();
if (p)
   free(p);
p = malloc(strlen(pt) + 1);
strcpy(p, pt);

Harald

At 20:17 15.01.2006 +0200, you wrote:
>Here is the problem commented in code.
>
>//settings.h
>typedef struct {
>         u_char *mysetting;
>} SETTINGS;
>
>extern SETTINGS settings;
>
>//code
>static int ASPCallback (char *pASPFunction, FILE *stream)
>{
>     if (strcmp(pASPFunction, "mysetting") == 0) {
>         fprintf(stream, settings.mysetting);
>         return(0);
>     }
>}
>
>int ProcessCgi(FILE * stream,REQUEST * req)
>{
>
>     NutHttpProcessPostQuery(stream, req);
>
>     //If i use this, results is strange characters to the "mysetting" field
>on the form
>     settings.mysetting=NutHttpGetParameter(req, "mysetting");
>
>     //next line works fine and "mysetting" field is string "somevalue",
>why???
>     settings.mysetting="somevalue";
>}
>
>thanks,
>-jari
>
>_______________________________________________
>En-Nut-Discussion mailing list
>En-Nut-Discussion at egnite.de
>http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion




More information about the En-Nut-Discussion mailing list