From ddd22b2f533db9c0da0bb262fbafa51f67c8587e Mon Sep 17 00:00:00 2001 From: jvoisin Date: Fri, 1 May 2026 00:36:32 +0200 Subject: Fix strncat/wcsncat Previously, no checks were done when __n <= __b, but strncat _appends_ after existing content, making this a overly broad check check. For example, with an 8-byte buffer containing "12345\0", strncat(buf, "ABCD", 4) would have the check skipped, but the result "12345ABCD\0" is 10 bytes, resulting in an overflow. This commit fixes this oversight, and adds a bunch of tests. --- tests/test_mbsnrtowcs_dynamic.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tests/test_mbsnrtowcs_dynamic.c') diff --git a/tests/test_mbsnrtowcs_dynamic.c b/tests/test_mbsnrtowcs_dynamic.c index 77b9082..58575d3 100644 --- a/tests/test_mbsnrtowcs_dynamic.c +++ b/tests/test_mbsnrtowcs_dynamic.c @@ -14,9 +14,7 @@ int main(int argc, char** argv) { srcp = src; mbsnrtowcs(buffer, &srcp, 2, 2, &st); - /* Unsafe: ask to write argc (10) wide chars into 4-element buffer. - * Before the fix, the else branch clamped source bytes instead of - * the output wide-char count, allowing destination overflow. */ + /* Unsafe: ask to write argc (10) wide chars into 4-element buffer. */ CHK_FAIL_START srcp = src; memset(&st, 0, sizeof(st)); -- cgit v1.3