psl.c: fix strndup replacement

Do not copy more bytes than the src string length.
This commit is contained in:
Giuseppe Scrivano 2015-02-28 18:52:47 +01:00
parent 225c557e23
commit 7a07205f1b
1 changed files with 7 additions and 1 deletions

View File

@ -93,7 +93,13 @@
static char *strndup(const char *s, size_t n)
{
char *dst = malloc(n + 1);
char *dst;
size_t s_len = strlen(s);
if (s_len > n)
n = s_len;
dst = malloc(n + 1);
if (dst) {
memcpy(dst, s, n);