evil_string: fix strndup() for non-NULL terminated strings.

If the given string is not null-terminated, then strlen() will go out
of boundaries, we must limit the lookup to given 'n' parameter.

To do so use strnlen(), that is a strlen() bounded by a maximum size.
This commit is contained in:
Gustavo Sverzut Barbieri 2017-03-29 10:11:01 -03:00
parent 9486225744
commit 13cd93f729
1 changed files with 1 additions and 2 deletions

View File

@ -18,10 +18,9 @@
char *
strndup(const char *str, size_t n)
{
size_t slen = strlen(str);
size_t slen = strnlen(str, n);
char *ret;
if (slen > n) slen = n;
ret = malloc (slen + 1);
if (!ret) return NULL;