mirror of
https://github.com/curl/curl.git
synced 2025-09-13 23:52:42 +03:00
tool_getparam: replace malloc + copy by dynbuf for --data
This commit is contained in:
parent
f37840a46e
commit
1dba44b2f1
|
@ -860,34 +860,24 @@ static ParameterError set_data(char subletter,
|
||||||
config->jsoned = TRUE;
|
config->jsoned = TRUE;
|
||||||
|
|
||||||
if(config->postfields) {
|
if(config->postfields) {
|
||||||
/* we already have a string, we append this one with a separating
|
/* we already have a string, append this one - perhaps with a separator */
|
||||||
&-letter */
|
struct curlx_dynbuf out;
|
||||||
char *oldpost = config->postfields;
|
curlx_dyn_init(&out, MAX_FILE2MEMORY);
|
||||||
curl_off_t oldlen = config->postfieldsize;
|
if(curlx_dyn_addn(&out, config->postfields,
|
||||||
curl_off_t newlen = oldlen + curlx_uztoso(size) + 2;
|
(size_t)config->postfieldsize))
|
||||||
config->postfields = malloc((size_t)newlen);
|
|
||||||
if(!config->postfields) {
|
|
||||||
Curl_safefree(oldpost);
|
|
||||||
Curl_safefree(postdata);
|
|
||||||
err = PARAM_NO_MEM;
|
err = PARAM_NO_MEM;
|
||||||
goto done;
|
|
||||||
}
|
/* skip the separator append for --json */
|
||||||
memcpy(config->postfields, oldpost, (size_t)oldlen);
|
if(!err && (subletter != 'f') && curlx_dyn_addn(&out, "&", 1))
|
||||||
if(subletter != 'f') {
|
err = PARAM_NO_MEM;
|
||||||
/* skip this treatment for --json */
|
|
||||||
/* use byte value 0x26 for '&' to accommodate non-ASCII platforms */
|
if(!err && curlx_dyn_addn(&out, postdata, size))
|
||||||
config->postfields[oldlen] = '\x26';
|
err = PARAM_NO_MEM;
|
||||||
memcpy(&config->postfields[oldlen + 1], postdata, size);
|
|
||||||
config->postfields[oldlen + 1 + size] = '\0';
|
config->postfieldsize = curlx_dyn_len(&out);
|
||||||
config->postfieldsize += size + 1;
|
free(config->postfields);
|
||||||
}
|
|
||||||
else {
|
|
||||||
memcpy(&config->postfields[oldlen], postdata, size);
|
|
||||||
config->postfields[oldlen + size] = '\0';
|
|
||||||
config->postfieldsize += size;
|
|
||||||
}
|
|
||||||
Curl_safefree(oldpost);
|
|
||||||
Curl_safefree(postdata);
|
Curl_safefree(postdata);
|
||||||
|
config->postfields = curlx_dyn_ptr(&out);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
config->postfields = postdata;
|
config->postfields = postdata;
|
||||||
|
|
|
@ -372,7 +372,6 @@ void single_transfer_cleanup(struct OperationConfig *config)
|
||||||
state->urls = NULL;
|
state->urls = NULL;
|
||||||
}
|
}
|
||||||
Curl_safefree(state->outfiles);
|
Curl_safefree(state->outfiles);
|
||||||
Curl_safefree(state->httpgetfields);
|
|
||||||
Curl_safefree(state->uploadfile);
|
Curl_safefree(state->uploadfile);
|
||||||
if(state->inglob) {
|
if(state->inglob) {
|
||||||
/* Free list of globbed upload files */
|
/* Free list of globbed upload files */
|
||||||
|
|
|
@ -88,8 +88,6 @@ ParameterError file2string(char **bufp, FILE *file)
|
||||||
return PARAM_OK;
|
return PARAM_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_FILE2MEMORY (1024*1024*1024) /* big enough ? */
|
|
||||||
|
|
||||||
ParameterError file2memory(char **bufp, size_t *size, FILE *file)
|
ParameterError file2memory(char **bufp, size_t *size, FILE *file)
|
||||||
{
|
{
|
||||||
if(file) {
|
if(file) {
|
||||||
|
|
|
@ -30,6 +30,8 @@ struct getout *new_getout(struct OperationConfig *config);
|
||||||
|
|
||||||
ParameterError file2string(char **bufp, FILE *file);
|
ParameterError file2string(char **bufp, FILE *file);
|
||||||
|
|
||||||
|
#define MAX_FILE2MEMORY (1024*1024*1024) /* big enough ? */
|
||||||
|
|
||||||
ParameterError file2memory(char **bufp, size_t *size, FILE *file);
|
ParameterError file2memory(char **bufp, size_t *size, FILE *file);
|
||||||
|
|
||||||
ParameterError str2num(long *val, const char *str);
|
ParameterError str2num(long *val, const char *str);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user