mirror of https://github.com/moparisthebest/curl
formdata: avoid "Argument cannot be negative" warning
... when converting a curl_off_t to size_t, by using CURL_ZERO_TERMINATED before passing the argument to the function. Detected by Coverity CID 1486590. Closes #7328 Assisted-by: Daniel Gustafsson
This commit is contained in:
parent
1ff1d9e179
commit
e081048c44
|
@ -865,8 +865,6 @@ CURLcode Curl_getformdata(struct Curl_easy *data,
|
||||||
|
|
||||||
if(post->flags & CURL_HTTPPOST_LARGE)
|
if(post->flags & CURL_HTTPPOST_LARGE)
|
||||||
clen = post->contentlen;
|
clen = post->contentlen;
|
||||||
if(!clen)
|
|
||||||
clen = -1;
|
|
||||||
|
|
||||||
if(post->flags & (HTTPPOST_FILENAME | HTTPPOST_READFILE)) {
|
if(post->flags & (HTTPPOST_FILENAME | HTTPPOST_READFILE)) {
|
||||||
if(!strcmp(file->contents, "-")) {
|
if(!strcmp(file->contents, "-")) {
|
||||||
|
@ -888,13 +886,21 @@ CURLcode Curl_getformdata(struct Curl_easy *data,
|
||||||
else if(post->flags & HTTPPOST_BUFFER)
|
else if(post->flags & HTTPPOST_BUFFER)
|
||||||
result = curl_mime_data(part, post->buffer,
|
result = curl_mime_data(part, post->buffer,
|
||||||
post->bufferlength? post->bufferlength: -1);
|
post->bufferlength? post->bufferlength: -1);
|
||||||
else if(post->flags & HTTPPOST_CALLBACK)
|
else if(post->flags & HTTPPOST_CALLBACK) {
|
||||||
/* the contents should be read with the callback and the size is set
|
/* the contents should be read with the callback and the size is set
|
||||||
with the contentslength */
|
with the contentslength */
|
||||||
|
if(!clen)
|
||||||
|
clen = -1;
|
||||||
result = curl_mime_data_cb(part, clen,
|
result = curl_mime_data_cb(part, clen,
|
||||||
fread_func, NULL, NULL, post->userp);
|
fread_func, NULL, NULL, post->userp);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
result = curl_mime_data(part, post->contents, (size_t) clen);
|
size_t uclen;
|
||||||
|
if(!clen)
|
||||||
|
uclen = CURL_ZERO_TERMINATED;
|
||||||
|
else
|
||||||
|
uclen = (size_t)clen;
|
||||||
|
result = curl_mime_data(part, post->contents, uclen);
|
||||||
#ifdef CURL_DOES_CONVERSIONS
|
#ifdef CURL_DOES_CONVERSIONS
|
||||||
/* Convert textual contents now. */
|
/* Convert textual contents now. */
|
||||||
if(!result && data && part->datasize)
|
if(!result && data && part->datasize)
|
||||||
|
|
Loading…
Reference in New Issue