diff options
author | Daniel Stenberg <daniel@haxx.se> | 2011-10-16 01:07:29 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2011-10-16 01:09:56 +0200 |
commit | 840eff44f2bea71acaa2a227998a97d01aacdc1f (patch) | |
tree | 2f0eddc19f513a85c8077b247ca090a548fccfd3 /lib/formdata.c | |
parent | ff03ee2a3c958065ad5fec657963deefb9b37ac0 (diff) | |
download | curl-840eff44f2bea71acaa2a227998a97d01aacdc1f.tar.gz |
formdata: ack read callback abort
When doing a multipart formpost with a read callback, and that callback
returns CURL_READFUNC_ABORT, that return code must be properly
propagated back and handled accordingly. Previously it would be handled
as a zero byte read which would cause a hang!
Added test case 587 to verify. It uses the lib554.c source code with a
small ifdef.
Reported by: Anton Bychkov
Bug: http://curl.haxx.se/mail/lib-2011-10/0097.html
Diffstat (limited to 'lib/formdata.c')
-rw-r--r-- | lib/formdata.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/formdata.c b/lib/formdata.c index edd35ede8..cbef51171 100644 --- a/lib/formdata.c +++ b/lib/formdata.c @@ -855,10 +855,11 @@ int curl_formget(struct curl_httppost *form, void *arg, do { nread = readfromfile(&temp, buffer, sizeof(buffer)); - if((nread == (size_t) -1) || (nread != append(arg, buffer, nread))) { - if(temp.fp) { + if((nread == (size_t) -1) || + (nread > sizeof(buffer)) || + (nread != append(arg, buffer, nread))) { + if(temp.fp) fclose(temp.fp); - } Curl_formclean(&data); return -1; } @@ -1269,6 +1270,13 @@ int Curl_FormInit(struct Form *form, struct FormData *formdata ) return 0; } +/* + * readfromfile() + * + * The read callback that this function may use can return a value larger than + * 'size' (which then this function returns) that indicates a problem and it + * must be properly dealt with + */ static size_t readfromfile(struct Form *form, char *buffer, size_t size) { @@ -1280,11 +1288,6 @@ static size_t readfromfile(struct Form *form, char *buffer, return 0; else nread = form->fread_func(buffer, 1, size, form->data->line); - - if(nread > size) - /* the read callback can return a value larger than the buffer but - treat any such as no data in this case */ - nread = 0; } else { if(!form->fp) { |