summaryrefslogtreecommitdiff
path: root/lib/formdata.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2021-07-01 00:14:22 +0200
committerDaniel Stenberg <daniel@haxx.se>2021-07-01 14:15:16 +0200
commite081048c44ec446bf6213d6b45a25ca51fd8a59d (patch)
tree0014ea28735e64b01c05d9f62c2b4a1f5b64c61c /lib/formdata.c
parent1ff1d9e179bb2a5b55d1323f9a74ccec361437b1 (diff)
downloadcurl-e081048c44ec446bf6213d6b45a25ca51fd8a59d.tar.gz
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
Diffstat (limited to 'lib/formdata.c')
-rw-r--r--lib/formdata.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/formdata.c b/lib/formdata.c
index f0e791a6c..ac7a0009c 100644
--- a/lib/formdata.c
+++ b/lib/formdata.c
@@ -865,8 +865,6 @@ CURLcode Curl_getformdata(struct Curl_easy *data,
if(post->flags & CURL_HTTPPOST_LARGE)
clen = post->contentlen;
- if(!clen)
- clen = -1;
if(post->flags & (HTTPPOST_FILENAME | HTTPPOST_READFILE)) {
if(!strcmp(file->contents, "-")) {
@@ -888,13 +886,21 @@ CURLcode Curl_getformdata(struct Curl_easy *data,
else if(post->flags & HTTPPOST_BUFFER)
result = curl_mime_data(part, post->buffer,
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
with the contentslength */
+ if(!clen)
+ clen = -1;
result = curl_mime_data_cb(part, clen,
fread_func, NULL, NULL, post->userp);
+ }
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
/* Convert textual contents now. */
if(!result && data && part->datasize)