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:
parent
9486225744
commit
13cd93f729
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue