mirror of
https://github.com/curl/curl.git
synced 2026-08-25 14:53:34 +03:00
tool_getparam: make data_urlencode avoid direct malloc
use aprintf() instead
This commit is contained in:
parent
3870d03b5d
commit
f37840a46e
1 changed files with 10 additions and 17 deletions
|
|
@ -637,25 +637,18 @@ static ParameterError data_urlencode(struct GlobalConfig *global,
|
||||||
char *enc = curl_easy_escape(NULL, postdata, (int)size);
|
char *enc = curl_easy_escape(NULL, postdata, (int)size);
|
||||||
Curl_safefree(postdata); /* no matter if it worked or not */
|
Curl_safefree(postdata); /* no matter if it worked or not */
|
||||||
if(enc) {
|
if(enc) {
|
||||||
/* replace (in-place) '%20' by '+' according to RFC1866 */
|
char *n;
|
||||||
size_t enclen = replace_url_encoded_space_by_plus(enc);
|
replace_url_encoded_space_by_plus(enc);
|
||||||
/* now make a string with the name from above and append the
|
|
||||||
encoded string */
|
|
||||||
size_t outlen = nlen + enclen + 2;
|
|
||||||
char *n = malloc(outlen);
|
|
||||||
if(!n) {
|
|
||||||
curl_free(enc);
|
|
||||||
return PARAM_NO_MEM;
|
|
||||||
}
|
|
||||||
if(nlen > 0) { /* only append '=' if we have a name */
|
if(nlen > 0) { /* only append '=' if we have a name */
|
||||||
msnprintf(n, outlen, "%.*s=%s", (int)nlen, nextarg, enc);
|
n = aprintf("%.*s=%s", (int)nlen, nextarg, enc);
|
||||||
size = outlen-1;
|
curl_free(enc);
|
||||||
|
if(!n)
|
||||||
|
return PARAM_NO_MEM;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
strcpy(n, enc);
|
n = enc;
|
||||||
size = outlen-2; /* since no '=' was inserted */
|
|
||||||
}
|
size = strlen(n);
|
||||||
curl_free(enc);
|
|
||||||
postdata = n;
|
postdata = n;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue