Fix strlen being used on uninitialized data

This commit is contained in:
Martijn van Beurden 2023-02-17 07:30:13 +01:00
parent cad22e0e3a
commit 5f39e88a88
1 changed files with 5 additions and 0 deletions

View File

@ -76,6 +76,11 @@ void local_strcat(char **dest, const char *source)
*dest = safe_realloc_add_3op_(*dest, ndest, /*+*/nsource, /*+*/1);
if(*dest == NULL)
die("out of memory growing string");
/* If ndest == 0, strlen in safe_strncat reads
* uninitialized data. To prevent that, set first character
* to zero */
if(ndest == 0)
*dest[0] = 0;
safe_strncat(*dest, source, outlen);
}