summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2021-05-06 10:25:56 +0200
committerDaniel Stenberg <daniel@haxx.se>2021-05-07 08:51:39 +0200
commit1763aceb0cbc14ebff425eeba3987322ac037a0e (patch)
tree4ae3d8a94a61f065d358200091c9ed724aa78ec0 /lib
parent817c01dacc3a344713607ee5da0ca2f9306d6c90 (diff)
downloadcurl-1763aceb0cbc14ebff425eeba3987322ac037a0e.tar.gz
http: limit the initial send amount to used upload buffer size
Previously this logic would cap the send to CURL_MAX_WRITE_SIZE bytes, but for the situations where a larger upload buffer has been set, this function can benefit from sending more bytes. With default size used, this does the same as before. Also changed the storage of the size to an 'unsigned int' as it is not allowed to be set larger than 2M. Also added cautions to the man pages about changing buffer sizes in run-time. Closes #7022
Diffstat (limited to 'lib')
-rw-r--r--lib/http.c16
-rw-r--r--lib/setopt.c2
-rw-r--r--lib/smb.c5
-rw-r--r--lib/smtp.c2
-rw-r--r--lib/urldata.h4
5 files changed, 14 insertions, 15 deletions
diff --git a/lib/http.c b/lib/http.c
index eece05513..4d8d94596 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -1273,14 +1273,6 @@ CURLcode Curl_buffer_send(struct dynbuf *in,
else
sendsize = size;
- /* We never send more than CURL_MAX_WRITE_SIZE bytes in one single chunk
- when we speak HTTPS, as if only a fraction of it is sent now, this data
- needs to fit into the normal read-callback buffer later on and that
- buffer is using this size.
- */
- if(sendsize > CURL_MAX_WRITE_SIZE)
- sendsize = CURL_MAX_WRITE_SIZE;
-
/* OpenSSL is very picky and we must send the SAME buffer pointer to the
library when we attempt to re-send this buffer. Sending the same data
is not enough, we must use the exact same address. For this reason, we
@@ -1293,6 +1285,14 @@ CURLcode Curl_buffer_send(struct dynbuf *in,
Curl_dyn_free(in);
return result;
}
+ /* We never send more than upload_buffer_size bytes in one single chunk
+ when we speak HTTPS, as if only a fraction of it is sent now, this data
+ needs to fit into the normal read-callback buffer later on and that
+ buffer is using this size.
+ */
+ if(sendsize > (size_t)data->set.upload_buffer_size)
+ sendsize = (size_t)data->set.upload_buffer_size;
+
memcpy(data->state.ulbuf, ptr, sendsize);
ptr = data->state.ulbuf;
}
diff --git a/lib/setopt.c b/lib/setopt.c
index 9ad984e79..1ded7ad3e 100644
--- a/lib/setopt.c
+++ b/lib/setopt.c
@@ -2198,7 +2198,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
else if(arg < UPLOADBUFFER_MIN)
arg = UPLOADBUFFER_MIN;
- data->set.upload_buffer_size = arg;
+ data->set.upload_buffer_size = (unsigned int)arg;
Curl_safefree(data->state.ulbuf); /* force a realloc next opportunity */
break;
diff --git a/lib/smb.c b/lib/smb.c
index 183bc12a5..0bf595ca0 100644
--- a/lib/smb.c
+++ b/lib/smb.c
@@ -627,9 +627,8 @@ static CURLcode smb_send_and_recv(struct Curl_easy *data, void **msg)
/* Check if there is data in the transfer buffer */
if(!smbc->send_size && smbc->upload_size) {
- size_t nread = smbc->upload_size > data->set.upload_buffer_size ?
- data->set.upload_buffer_size :
- smbc->upload_size;
+ size_t nread = smbc->upload_size > (size_t)data->set.upload_buffer_size ?
+ (size_t)data->set.upload_buffer_size : smbc->upload_size;
data->req.upload_fromhere = data->state.ulbuf;
result = Curl_fillreadbuffer(data, nread, &nread);
if(result && result != CURLE_AGAIN)
diff --git a/lib/smtp.c b/lib/smtp.c
index be4cd675c..e1560f583 100644
--- a/lib/smtp.c
+++ b/lib/smtp.c
@@ -1821,7 +1821,7 @@ CURLcode Curl_smtp_escape_eob(struct Curl_easy *data, const ssize_t nread)
return CURLE_OUT_OF_MEMORY;
}
}
- DEBUGASSERT(data->set.upload_buffer_size >= (size_t)nread);
+ DEBUGASSERT((size_t)data->set.upload_buffer_size >= (size_t)nread);
/* Have we already sent part of the EOB? */
eob_sent = smtp->eob;
diff --git a/lib/urldata.h b/lib/urldata.h
index 04daf778a..421a86b62 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -1722,8 +1722,8 @@ struct UserDefined {
struct ssl_general_config general_ssl; /* general user defined SSL stuff */
long dns_cache_timeout; /* DNS cache timeout */
long buffer_size; /* size of receive buffer to use */
- size_t upload_buffer_size; /* size of upload buffer to use,
- keep it >= CURL_MAX_WRITE_SIZE */
+ unsigned int upload_buffer_size; /* size of upload buffer to use,
+ keep it >= CURL_MAX_WRITE_SIZE */
void *private_data; /* application-private data */
struct curl_slist *http200aliases; /* linked list of aliases for http200 */
unsigned char ipver; /* the CURL_IPRESOLVE_* defines in the public header