about summary refs log tree commit diff
diff options
context:
space:
mode:
authorQuentin Rameau <quinq@fifth.space>2018-11-11 09:25:26 +0100
committerRich Felker <dalias@aerifal.cx>2018-12-02 09:24:15 -0500
commitd9bdfd1644320ab916ea31d95da4bf641042209a (patch)
tree0e0bc5200c4d52dbea7ee61c5b1b44ecb7c64391
parent39ef612aa193cc6e954ac5a01574300ccd4b7ef9 (diff)
downloadmusl-d9bdfd1644320ab916ea31d95da4bf641042209a.tar.gz
musl-d9bdfd1644320ab916ea31d95da4bf641042209a.tar.xz
musl-d9bdfd1644320ab916ea31d95da4bf641042209a.zip
fix memccpy to not access buffer past given size
memccpy would return a pointer over the given size when c is not
found in the source buffer and n reaches 0.
-rw-r--r--src/string/memccpy.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/string/memccpy.c b/src/string/memccpy.c
index f515581c..00c18e2b 100644
--- a/src/string/memccpy.c
+++ b/src/string/memccpy.c
@@ -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;
 }