mirror of
https://github.com/moparisthebest/curl
synced 2024-08-13 17:03:50 -04:00
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
This commit is contained in:
parent
0126b4a959
commit
f851f76857
@ -1134,15 +1134,17 @@ CURLcode Curl_getformdata(struct SessionHandle *data,
|
|||||||
/* it should be noted that for the HTTPPOST_FILENAME and
|
/* it should be noted that for the HTTPPOST_FILENAME and
|
||||||
HTTPPOST_CALLBACK cases the ->showfilename struct member is always
|
HTTPPOST_CALLBACK cases the ->showfilename struct member is always
|
||||||
assigned at this point */
|
assigned at this point */
|
||||||
char *filebasename=
|
if(post->showfilename || (post->flags & HTTPPOST_FILENAME)) {
|
||||||
(!post->showfilename)?strippath(post->contents):NULL;
|
char *filebasename=
|
||||||
|
(!post->showfilename)?strippath(post->contents):NULL;
|
||||||
|
|
||||||
result = AddFormDataf(&form, &size,
|
result = AddFormDataf(&form, &size,
|
||||||
"; filename=\"%s\"",
|
"; filename=\"%s\"",
|
||||||
(post->showfilename?post->showfilename:
|
(post->showfilename?post->showfilename:
|
||||||
filebasename));
|
filebasename));
|
||||||
if(filebasename)
|
if(filebasename)
|
||||||
free(filebasename);
|
free(filebasename);
|
||||||
|
}
|
||||||
|
|
||||||
if(result)
|
if(result)
|
||||||
break;
|
break;
|
||||||
|
@ -39,13 +39,13 @@ s/^------------------------------[a-z0-9]*/------------------------------/
|
|||||||
s/boundary=----------------------------[a-z0-9]*/boundary=----------------------------/
|
s/boundary=----------------------------[a-z0-9]*/boundary=----------------------------/
|
||||||
</strippart>
|
</strippart>
|
||||||
# Note that the stripping above removes 12 bytes from every occurance of the
|
# Note that the stripping above removes 12 bytes from every occurance of the
|
||||||
# boundary string and since 4 of them are in the body contents, we see
|
# boundary string and since 5 of them are in the body contents, we see
|
||||||
# 415 - (4*12) here == 367 bytes.
|
# (5*12) == 60 bytes less
|
||||||
<protocol>
|
<protocol>
|
||||||
POST /554 HTTP/1.1
|
POST /554 HTTP/1.1
|
||||||
Host: %HOSTIP:%HTTPPORT
|
Host: %HOSTIP:%HTTPPORT
|
||||||
Accept: */*
|
Accept: */*
|
||||||
Content-Length: 415
|
Content-Length: 561
|
||||||
Expect: 100-continue
|
Expect: 100-continue
|
||||||
Content-Type: multipart/form-data; boundary=----------------------------
|
Content-Type: multipart/form-data; boundary=----------------------------
|
||||||
|
|
||||||
@ -54,6 +54,11 @@ Content-Disposition: form-data; name="sendfile"; filename="postit2.c"
|
|||||||
|
|
||||||
this is what we post to the silly web server
|
this is what we post to the silly web server
|
||||||
|
|
||||||
|
------------------------------
|
||||||
|
Content-Disposition: form-data; name="callbackdata"
|
||||||
|
|
||||||
|
this is what we post to the silly web server
|
||||||
|
|
||||||
------------------------------
|
------------------------------
|
||||||
Content-Disposition: form-data; name="filename"
|
Content-Disposition: form-data; name="filename"
|
||||||
|
|
||||||
|
@ -64,6 +64,7 @@ int test(char *URL)
|
|||||||
struct curl_httppost *formpost=NULL;
|
struct curl_httppost *formpost=NULL;
|
||||||
struct curl_httppost *lastptr=NULL;
|
struct curl_httppost *lastptr=NULL;
|
||||||
struct WriteThis pooh;
|
struct WriteThis pooh;
|
||||||
|
struct WriteThis pooh2;
|
||||||
|
|
||||||
if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
|
if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
|
||||||
fprintf(stderr, "curl_global_init() failed\n");
|
fprintf(stderr, "curl_global_init() failed\n");
|
||||||
@ -85,6 +86,23 @@ int test(char *URL)
|
|||||||
if(formrc)
|
if(formrc)
|
||||||
printf("curl_formadd(1) = %d\n", (int)formrc);
|
printf("curl_formadd(1) = %d\n", (int)formrc);
|
||||||
|
|
||||||
|
/* Now add the same data with another name and make it not look like
|
||||||
|
a file upload but still using the callback */
|
||||||
|
|
||||||
|
pooh2.readptr = data;
|
||||||
|
pooh2.sizeleft = strlen(data);
|
||||||
|
|
||||||
|
/* Fill in the file upload field */
|
||||||
|
formrc = curl_formadd(&formpost,
|
||||||
|
&lastptr,
|
||||||
|
CURLFORM_COPYNAME, "callbackdata",
|
||||||
|
CURLFORM_STREAM, &pooh2,
|
||||||
|
CURLFORM_CONTENTSLENGTH, pooh2.sizeleft,
|
||||||
|
CURLFORM_END);
|
||||||
|
|
||||||
|
if(formrc)
|
||||||
|
printf("curl_formadd(1) = %d\n", (int)formrc);
|
||||||
|
|
||||||
/* Fill in the filename field */
|
/* Fill in the filename field */
|
||||||
formrc = curl_formadd(&formpost,
|
formrc = curl_formadd(&formpost,
|
||||||
&lastptr,
|
&lastptr,
|
||||||
|
Loading…
Reference in New Issue
Block a user