From 7359c88be34ffc9ae0042826f0778f89d9a82314 Mon Sep 17 00:00:00 2001 From: Brooks Davis Date: Thu, 1 Aug 2019 23:28:54 +0000 Subject: [PATCH] MFC r350160: Avoid copying too much from the input string. This avoids reading past the end of the static strings. On a system with bounds checking these tests fault. Reviewed by: asomers Obtained from: CheriBSD Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D21004 --- lib/libc/tests/string/wcsnlen_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libc/tests/string/wcsnlen_test.c b/lib/libc/tests/string/wcsnlen_test.c index ec11938b19a..07870e3a5ca 100644 --- a/lib/libc/tests/string/wcsnlen_test.c +++ b/lib/libc/tests/string/wcsnlen_test.c @@ -65,7 +65,7 @@ test_wcsnlen(const wchar_t *s) for (i = 0; i <= 1; i++) { for (bufsize = 0; bufsize <= size + 10; bufsize++) { s1 = makebuf(bufsize * sizeof(wchar_t), i); - wmemcpy(s1, s, bufsize); + wmemcpy(s1, s, bufsize <= size ? bufsize : size); len = (size > bufsize) ? bufsize : size - 1; ATF_CHECK(wcsnlen(s1, bufsize) == len); } -- 2.45.0