aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tool_setopt.c19
-rw-r--r--tests/data/test14046
-rw-r--r--tests/libtest/lib643.c16
3 files changed, 25 insertions, 16 deletions
diff --git a/src/tool_setopt.c b/src/tool_setopt.c
index 967241d64..b0f319814 100644
--- a/src/tool_setopt.c
+++ b/src/tool_setopt.c
@@ -487,8 +487,12 @@ static CURLcode libcurl_generate_mime(curl_mime *mime, int *mimeno)
Curl_safefree(data);
if(!escaped)
return CURLE_OUT_OF_MEMORY;
- CODE3("curl_mime_data(part%d, \"%s\", %" CURL_FORMAT_CURL_OFF_T ");",
- *mimeno, escaped, size);
+ if(size >= 0)
+ CODE3("curl_mime_data(part%d, \"%s\", %" CURL_FORMAT_CURL_OFF_T ");",
+ *mimeno, escaped, size);
+ else
+ CODE2("curl_mime_data(part%d, \"%s\", CURL_ZERO_TERMINATED);",
+ *mimeno, escaped);
break;
case MIMEKIND_MULTIPART:
ret = libcurl_generate_mime(part->arg, &i);
@@ -515,12 +519,17 @@ static CURLcode libcurl_generate_mime(curl_mime *mime, int *mimeno)
escaped = c_escape(part->name, part->namesize);
if(!escaped)
return CURLE_OUT_OF_MEMORY;
+ /* Are there any nul byte in name? */
for(cp = part->name; *cp; cp++)
;
- size = (cp == part->name + part->namesize)?
- (curl_off_t) -1: (curl_off_t) part->namesize;
- CODE3("curl_mime_name(part%d, \"%s\", %" CURL_FORMAT_CURL_OFF_T ");",
+ if(cp != part->name + part->namesize) {
+ size = (curl_off_t) part->namesize;
+ CODE3("curl_mime_name(part%d, \"%s\", %" CURL_FORMAT_CURL_OFF_T ");",
*mimeno, escaped, size);
+ }
+ else
+ CODE2("curl_mime_name(part%d, \"%s\", CURL_ZERO_TERMINATED);",
+ *mimeno, escaped);
}
if(part->mimetype) {
diff --git a/tests/data/test1404 b/tests/data/test1404
index 60ed58a16..a3ec66ef7 100644
--- a/tests/data/test1404
+++ b/tests/data/test1404
@@ -123,8 +123,8 @@ int main(int argc, char *argv[])
curl_easy_setopt(hnd, CURLOPT_HEADER, 1L);
mime1 = curl_mime_init(hnd);
part1 = curl_mime_addpart(mime1);
- curl_mime_data(part1, "value", -1);
- curl_mime_name(part1, "name", -1);
+ curl_mime_data(part1, "value", CURL_ZERO_TERMINATED);
+ curl_mime_name(part1, "name", CURL_ZERO_TERMINATED);
part1 = curl_mime_addpart(mime1);
mime2 = curl_mime_init(hnd);
part2 = curl_mime_addpart(mime2);
@@ -138,7 +138,7 @@ int main(int argc, char *argv[])
slist1 = NULL;
curl_mime_subparts(part1, mime2);
mime2 = NULL;
- curl_mime_name(part1, "file", -1);
+ curl_mime_name(part1, "file", CURL_ZERO_TERMINATED);
curl_easy_setopt(hnd, CURLOPT_MIMEPOST, mime1);
curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped");
curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
diff --git a/tests/libtest/lib643.c b/tests/libtest/lib643.c
index ea5a96740..b2698f076 100644
--- a/tests/libtest/lib643.c
+++ b/tests/libtest/lib643.c
@@ -113,7 +113,7 @@ static int once(char *URL, bool oldstyle)
/* Fill in the file upload part */
if(oldstyle) {
- res = curl_mime_name(part, "sendfile", -1);
+ res = curl_mime_name(part, "sendfile", CURL_ZERO_TERMINATED);
if(!res)
res = curl_mime_data_cb(part, datasize, read_callback,
NULL, NULL, &pooh);
@@ -122,7 +122,7 @@ static int once(char *URL, bool oldstyle)
}
else {
/* new style */
- res = curl_mime_name(part, "sendfile alternative", -1);
+ res = curl_mime_name(part, "sendfile alternative", CURL_ZERO_TERMINATED);
if(!res)
res = curl_mime_data_cb(part, datasize, read_callback,
NULL, NULL, &pooh);
@@ -151,7 +151,7 @@ static int once(char *URL, bool oldstyle)
return TEST_ERR_MAJOR_BAD;
}
/* Fill in the file upload part */
- res = curl_mime_name(part, "callbackdata", -1);
+ res = curl_mime_name(part, "callbackdata", CURL_ZERO_TERMINATED);
if(!res)
res = curl_mime_data_cb(part, datasize, read_callback,
NULL, NULL, &pooh2);
@@ -169,7 +169,7 @@ static int once(char *URL, bool oldstyle)
}
/* Fill in the filename field */
- res = curl_mime_name(part, "filename", -1);
+ res = curl_mime_name(part, "filename", CURL_ZERO_TERMINATED);
if(!res)
res = curl_mime_data(part,
#ifdef CURL_DOES_CONVERSIONS
@@ -179,7 +179,7 @@ static int once(char *URL, bool oldstyle)
#else
"postit2.c",
#endif
- -1);
+ CURL_ZERO_TERMINATED);
if(res)
printf("curl_mime_xxx(3) = %s\n", curl_easy_strerror(res));
@@ -193,7 +193,7 @@ static int once(char *URL, bool oldstyle)
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
- res = curl_mime_name(part, "submit", -1);
+ res = curl_mime_name(part, "submit", CURL_ZERO_TERMINATED);
if(!res)
res = curl_mime_data(part,
#ifdef CURL_DOES_CONVERSIONS
@@ -203,7 +203,7 @@ static int once(char *URL, bool oldstyle)
#else
"send",
#endif
- -1);
+ CURL_ZERO_TERMINATED);
if(res)
printf("curl_mime_xxx(4) = %s\n", curl_easy_strerror(res));
@@ -216,7 +216,7 @@ static int once(char *URL, bool oldstyle)
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
- res = curl_mime_name(part, "somename", -1);
+ res = curl_mime_name(part, "somename", CURL_ZERO_TERMINATED);
if(!res)
res = curl_mime_filename(part, "somefile.txt");
if(!res)