mirror of
https://github.com/curl/curl.git
synced 2025-02-23 15:10:03 +08:00
Allow CURLOPT_COPYPOSTFIELDS with explicit data size = 0
This commit is contained in:
parent
bef2e7f2ff
commit
8f5909b664
14
lib/url.c
14
lib/url.c
@ -1036,10 +1036,10 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
|
|||||||
result = Curl_setstropt(&data->set.str[STRING_COPYPOSTFIELDS], argptr);
|
result = Curl_setstropt(&data->set.str[STRING_COPYPOSTFIELDS], argptr);
|
||||||
else {
|
else {
|
||||||
/*
|
/*
|
||||||
* Check that request length does not overflow the size_t type.
|
* Check that requested length does not overflow the size_t type.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((data->set.postfieldsize < 1) ||
|
if ((data->set.postfieldsize < 0) ||
|
||||||
((sizeof(curl_off_t) != sizeof(size_t)) &&
|
((sizeof(curl_off_t) != sizeof(size_t)) &&
|
||||||
(data->set.postfieldsize > (curl_off_t)((size_t)-1))))
|
(data->set.postfieldsize > (curl_off_t)((size_t)-1))))
|
||||||
result = CURLE_OUT_OF_MEMORY;
|
result = CURLE_OUT_OF_MEMORY;
|
||||||
@ -1047,12 +1047,20 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
|
|||||||
char * p;
|
char * p;
|
||||||
|
|
||||||
(void) Curl_setstropt(&data->set.str[STRING_COPYPOSTFIELDS], NULL);
|
(void) Curl_setstropt(&data->set.str[STRING_COPYPOSTFIELDS], NULL);
|
||||||
p = malloc(data->set.postfieldsize);
|
|
||||||
|
/* Allocate even when size == 0. This satisfies the need of possible
|
||||||
|
later address compare to detect the COPYPOSTFIELDS mode, and
|
||||||
|
to mark that postfields is used rather than read function or
|
||||||
|
form data.
|
||||||
|
*/
|
||||||
|
p = malloc(data->set.postfieldsize? data->set.postfieldsize: 1);
|
||||||
|
|
||||||
if (!p)
|
if (!p)
|
||||||
result = CURLE_OUT_OF_MEMORY;
|
result = CURLE_OUT_OF_MEMORY;
|
||||||
else {
|
else {
|
||||||
|
if (data->set.postfieldsize)
|
||||||
memcpy(p, argptr, data->set.postfieldsize);
|
memcpy(p, argptr, data->set.postfieldsize);
|
||||||
|
|
||||||
data->set.str[STRING_COPYPOSTFIELDS] = p;
|
data->set.str[STRING_COPYPOSTFIELDS] = p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user