Skip to content

Commit

Permalink
CURLFORM_BUFFER: insert filename as documented
Browse files Browse the repository at this point in the history
A regression where CURLFORM_BUFFER stopped to properly insert the file
name part in the formpart. Bug introduced in commit f851f76.

Added CURLFORM_BUFFER use to test 554 to verify this.

Bug: http://curl.haxx.se/mail/lib-2011-07/0176.html
Reported by: Henry Ludemann
  • Loading branch information
bagder committed Aug 8, 2011
1 parent 3ef6418 commit 45d883d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 41 deletions.
3 changes: 0 additions & 3 deletions TODO-RELEASE
Expand Up @@ -36,9 +36,6 @@ To be addressed in 7.21.8 (or 7.22.0?)
301 - "Forcing select on vista"
http://curl.haxx.se/mail/lib-2011-07/0128.html

302 - "Problem with file upload using CURLFORM_BUFFER" (Regression)
Henry Ludemann http://curl.haxx.se/mail/lib-2011-07/0176.html

303 - "Added AUTH NTLM for SMTP" Steve Holme
http://curl.haxx.se/mail/lib-2011-07/0186.html and
http://curl.haxx.se/mail/lib-2011-08/0008.html
Expand Down
49 changes: 12 additions & 37 deletions lib/formdata.c
Expand Up @@ -459,7 +459,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
if(current_form->flags & HTTPPOST_FILENAME) {
if(filename) {
if((current_form = AddFormInfo(strdup(filename),
NULL, current_form)) == NULL)
NULL, current_form)) == NULL)
return_value = CURL_FORMADD_MEMORY;
}
else
Expand All @@ -484,46 +484,18 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
break;
}

case CURLFORM_BUFFER:
{
const char *filename = array_state?array_value:
va_arg(params, char *);

if(current_form->value) {
if(current_form->flags & HTTPPOST_BUFFER) {
if(filename) {
if((current_form = AddFormInfo(strdup(filename),
NULL, current_form)) == NULL)
return_value = CURL_FORMADD_MEMORY;
}
else
return_value = CURL_FORMADD_NULL;
}
else
return_value = CURL_FORMADD_OPTION_TWICE;
}
else {
if(filename) {
current_form->value = strdup(filename);
if(!current_form->value)
return_value = CURL_FORMADD_MEMORY;
}
else
return_value = CURL_FORMADD_NULL;
current_form->flags |= HTTPPOST_BUFFER;
}
break;
}

case CURLFORM_BUFFERPTR:
current_form->flags |= HTTPPOST_PTRBUFFER;
current_form->flags |= HTTPPOST_PTRBUFFER|HTTPPOST_BUFFER;
if(current_form->buffer)
return_value = CURL_FORMADD_OPTION_TWICE;
else {
char *buffer =
array_state?array_value:va_arg(params, char *);
if(buffer)
if(buffer) {
current_form->buffer = buffer; /* store for the moment */
current_form->value = buffer; /* make it non-NULL to be accepted
as fine */
}
else
return_value = CURL_FORMADD_NULL;
}
Expand Down Expand Up @@ -564,8 +536,8 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
if(current_form->flags & HTTPPOST_FILENAME) {
if(contenttype) {
if((current_form = AddFormInfo(NULL,
strdup(contenttype),
current_form)) == NULL)
strdup(contenttype),
current_form)) == NULL)
return_value = CURL_FORMADD_MEMORY;
}
else
Expand Down Expand Up @@ -603,6 +575,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
break;
}
case CURLFORM_FILENAME:
case CURLFORM_BUFFER:
{
const char *filename = array_state?array_value:
va_arg(params, char *);
Expand All @@ -619,6 +592,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
}
default:
return_value = CURL_FORMADD_UNKNOWN_OPTION;
break;
}
}

Expand Down Expand Up @@ -922,7 +896,8 @@ void curl_formfree(struct curl_httppost *form)

if(!(form->flags & HTTPPOST_PTRNAME) && form->name)
free(form->name); /* free the name */
if(!(form->flags & (HTTPPOST_PTRCONTENTS|HTTPPOST_CALLBACK)) &&
if(!(form->flags &
(HTTPPOST_PTRCONTENTS|HTTPPOST_BUFFER|HTTPPOST_CALLBACK)) &&
form->contents)
free(form->contents); /* free the contents */
if(form->contenttype)
Expand Down
7 changes: 6 additions & 1 deletion tests/data/test554
Expand Up @@ -45,7 +45,7 @@ s/boundary=----------------------------[a-z0-9]*/boundary=----------------------
POST /554 HTTP/1.1
Host: %HOSTIP:%HTTPPORT
Accept: */*
Content-Length: 561
Content-Length: 732
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------

Expand All @@ -67,6 +67,11 @@ postit2.c
Content-Disposition: form-data; name="submit"

send
------------------------------
Content-Disposition: form-data; name="somename"; filename="somefile.txt"
Content-Type: application/octet-stream

blah blah
--------------------------------
</protocol>
</verify>
Expand Down
10 changes: 10 additions & 0 deletions tests/libtest/lib554.c
Expand Up @@ -136,6 +136,16 @@ int test(char *URL)
if(formrc)
printf("curl_formadd(3) = %d\n", (int)formrc);

formrc = curl_formadd(&formpost, &lastptr,
CURLFORM_COPYNAME, "somename",
CURLFORM_BUFFER, "somefile.txt",
CURLFORM_BUFFERPTR, "blah blah",
CURLFORM_BUFFERLENGTH, 9,
CURLFORM_END);

if(formrc)
printf("curl_formadd(4) = %d\n", (int)formrc);

if ((curl = curl_easy_init()) == NULL) {
fprintf(stderr, "curl_easy_init() failed\n");
curl_formfree(formpost);
Expand Down

0 comments on commit 45d883d

Please sign in to comment.