lib: add and use Curl_strndup()

The Curl_strndup() function is similar to memdup(), but copies 'n' bytes
then adds a terminating null byte ('\0').

Closes #12251
This commit is contained in:
Daniel Stenberg 2023-11-02 13:47:15 +01:00
parent fdaed85b02
commit d3b3ba35a5
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
7 changed files with 30 additions and 18 deletions

View file

@ -603,9 +603,9 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
app passed in a bad combo, so we better check for that first. */
if(form->name) {
/* copy name (without strdup; possibly not null-terminated) */
form->name = Curl_memdup(form->name, form->namelength?
form->namelength:
strlen(form->name) + 1);
form->name = Curl_strndup(form->name, form->namelength?
form->namelength:
strlen(form->name));
}
if(!form->name) {
return_value = CURL_FORMADD_MEMORY;