psl.c: fix strndup replacement
Do not copy more bytes than the src string length.
This commit is contained in:
parent
225c557e23
commit
7a07205f1b
|
@ -93,7 +93,13 @@
|
||||||
|
|
||||||
static char *strndup(const char *s, size_t n)
|
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) {
|
if (dst) {
|
||||||
memcpy(dst, s, n);
|
memcpy(dst, s, n);
|
||||||
|
|
Loading…
Reference in New Issue