cURL / Mailing Lists / curl-library / Single Mail

curl-library

bug in curl_formget()

From: Aaron Orenstein <aorenste_at_gmail.com>
Date: Fri, 10 Jun 2011 02:02:43 -0400

First time submitting a bug/patch - hopefully this is the right forum.

I think I've come across a bug in curl_formget() where it's not closing the
files that it's opened. The problem is that it looks like readfromfile()
has a '>' where there should be a '<':

--- a/vendor/libcurl/lib/formdata.c
+++ b/vendor/libcurl/lib/formdata.c
@@ -1418,7 +1418,7 @@ static size_t readfromfile(struct Form *form, char
*buffer,
     }
     nread = fread(buffer, 1, size, form->fp);
   }
- if(!nread || nread > size) {
+ if(nread < size) {
     /* this is the last chunk from the file, move on */
     if(!callback) {
       fclose(form->fp);
Of course this expects that the callback will return a full buffer and not
just a partial one - I couldn't tell what was allowed. If a partial buffer
is a valid return then instead the proper fix would be:

--- a/vendor/libcurl/lib/formdata.c
+++ b/vendor/libcurl/lib/formdata.c
@@ -997,7 +997,7 @@ int curl_formget(struct curl_httppost *form, void *arg,
           Curl_formclean(&data);
           return -1;
         }
- } while(nread == sizeof(buffer));
+ } while(nread != 0);
     }
     else {
       if(ptr->length != append(arg, ptr->line, ptr->length)) {
This will end up calling readfromfile() until it returns 0.

Thanks
- Aaron

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-06-10