tool_getparam: make data_urlencode avoid direct malloc

use aprintf() instead
This commit is contained in:
Daniel Stenberg 2024-01-08 17:00:05 +01:00
parent 3870d03b5d
commit f37840a46e
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -637,25 +637,18 @@ static ParameterError data_urlencode(struct GlobalConfig *global,
char *enc = curl_easy_escape(NULL, postdata, (int)size);
Curl_safefree(postdata); /* no matter if it worked or not */
if(enc) {
/* replace (in-place) '%20' by '+' according to RFC1866 */
size_t enclen = 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;
}
char *n;
replace_url_encoded_space_by_plus(enc);
if(nlen > 0) { /* only append '=' if we have a name */
msnprintf(n, outlen, "%.*s=%s", (int)nlen, nextarg, enc);
size = outlen-1;
n = aprintf("%.*s=%s", (int)nlen, nextarg, enc);
curl_free(enc);
if(!n)
return PARAM_NO_MEM;
}
else {
strcpy(n, enc);
size = outlen-2; /* since no '=' was inserted */
}
curl_free(enc);
else
n = enc;
size = strlen(n);
postdata = n;
}
else