ralloc: Use strnlen() inside of strncat()
If the str is long or isn't null-terminated, strlen() could take a lot of time or even crash. I don't know why was it used in the first place, maybe for platforms without strnlen(), but strnlen() is already used inside of ralloc_strndup(), so this change should not additionally break anything. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
This commit is contained in:

committed by
Timothy Arceri

parent
4a47247523
commit
cf164d9e97
@@ -405,12 +405,7 @@ ralloc_strcat(char **dest, const char *str)
|
|||||||
bool
|
bool
|
||||||
ralloc_strncat(char **dest, const char *str, size_t n)
|
ralloc_strncat(char **dest, const char *str, size_t n)
|
||||||
{
|
{
|
||||||
/* Clamp n to the string length */
|
return cat(dest, str, strnlen(str, n));
|
||||||
size_t str_length = strlen(str);
|
|
||||||
if (str_length < n)
|
|
||||||
n = str_length;
|
|
||||||
|
|
||||||
return cat(dest, str, n);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
|
Reference in New Issue
Block a user