fix memccpy to not access buffer past given size
authorQuentin Rameau <quinq@fifth.space>
Sun, 11 Nov 2018 08:25:26 +0000 (09:25 +0100)
committerRich Felker <dalias@aerifal.cx>
Sun, 2 Dec 2018 14:24:15 +0000 (09:24 -0500)
memccpy would return a pointer over the given size when c is not
found in the source buffer and n reaches 0.

src/string/memccpy.c

index f515581..00c18e2 100644 (file)
@@ -29,6 +29,6 @@ void *memccpy(void *restrict dest, const void *restrict src, int c, size_t n)
 #endif
        for (; n && (*d=*s)!=c; n--, s++, d++);
 tail:
-       if (*s==c) return d+1;
+       if (n && *s==c) return d+1;
        return 0;
 }