cURL / Mailing Lists / curl-library / Single Mail

curl-library

formparse patch

From: Peter Todd <peter_at_starnix.com>
Date: Fri, 10 Aug 2001 15:42:50 -0400

I ran into a problem with your formparse code, it truncates POSTS over
4k Anyway I made a quick-n-dirty patch.

I'll use your cool new form thingy I saw on the list archives when it
comes out. Any estimates for how long I'll have to wait?

I'm not on the list BTW so please CC me any replies.

--- formdata.c Tue Jun 5 07:27:40 2001
+++ /usr/src/curl-7.8/lib/formdata.c Tue Aug 7 18:17:20 2001
@@ -102,7 +102,7 @@
   /* nextarg MUST be a string in the format 'name=contents' and we'll
      build a linked list with the info */
   char name[256];
- char contents[4096]="";
+ char *contents;
   char major[128];
   char minor[128];
   long flags = 0;
@@ -115,7 +115,12 @@
   struct HttpPost *subpost; /* a sub-node */
   unsigned int i;

- if(1 <= sscanf(input, "%255[^ =] = %4095[^\n]", name, contents)) {
+ /* Preallocate contents to the length of input to make sure we don't
+ overwrite anything. */
+ contents = malloc(strlen(input));
+ contents[0] = '\000';
+
+ if(1 <= sscanf(input, "%255[^ =] = %[^\n]", name, contents)) {
     /* the input was using the correct format */
     contp = contents;

@@ -156,6 +161,7 @@
            if(2 != sscanf(type, "%127[^/]/%127[^,\n]",
                           major, minor)) {
              fprintf(stderr, "Illegally formatted content-type field!\n");
+ free(contents);
              return 2; /* illegal content-type syntax! */
            }
            /* now point beyond the content-type specifier */
@@ -287,8 +293,10 @@
   }
   else {
     fprintf(stderr, "Illegally formatted input field!\n");
+ free(contents);
     return 1;
   }
+ free(contents);
   return 0;
 }

_______________________________________________
Curl-library mailing list
http://curl.haxx.se/libcurl/
Received on 2001-08-12