From f851f768578dc096c561d57ba07ffd1004d504c0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 17 Jun 2011 22:21:36 +0200 Subject: CURLFORM_STREAM: acknowledge CURLFORM_FILENAME The CURLFORM_STREAM is documented to only insert a file name (and thus look like a file upload) in the part if CURLFORM_FILENAME is set, but in reality it always inserted a filename="" and if CURLFORM_FILENAME wasn't set, it would insert insert rubbish (or possibly crash). This is now fixed to work as documented, and test 554 has been extended to verify this. Reported by: Sascha Swiercy Bug: http://curl.haxx.se/mail/lib-2011-06/0070.html --- lib/formdata.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/formdata.c b/lib/formdata.c index 5419371de..aa5a79ac1 100644 --- a/lib/formdata.c +++ b/lib/formdata.c @@ -1134,15 +1134,17 @@ CURLcode Curl_getformdata(struct SessionHandle *data, /* it should be noted that for the HTTPPOST_FILENAME and HTTPPOST_CALLBACK cases the ->showfilename struct member is always assigned at this point */ - char *filebasename= - (!post->showfilename)?strippath(post->contents):NULL; - - result = AddFormDataf(&form, &size, - "; filename=\"%s\"", - (post->showfilename?post->showfilename: - filebasename)); - if(filebasename) - free(filebasename); + if(post->showfilename || (post->flags & HTTPPOST_FILENAME)) { + char *filebasename= + (!post->showfilename)?strippath(post->contents):NULL; + + result = AddFormDataf(&form, &size, + "; filename=\"%s\"", + (post->showfilename?post->showfilename: + filebasename)); + if(filebasename) + free(filebasename); + } if(result) break; -- cgit v1.2.3