From nobody Thu Jan 1 22:21:49 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dj1Wy2bRyz6Lpp1 for ; Thu, 01 Jan 2026 22:21:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dj1Wy0MDgz3C4R for ; Thu, 01 Jan 2026 22:21:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1767306110; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=irbJbPpUeLGfNtbC+26lE3WxIkPbtHQfvJ61omAWAbs=; b=RUZFy51io1zdGnHZs7TEPAYPAA5O8+de+PwbXIzbJPWXIvBKOYtrCmMHd5OaO9kug1ChND NGWypC7HcjW609QpGmT6hMtG4glv7nDaFUXgawjXKSvuXkwusgA5YmRKYicd9FT+tASHTs XHa3Ott2F8DVQJuRasqJbJ/mSJdnOrFaRI41FzgVky+rIdePoSJRvfMrKitBvhiTnP25OU lmVsi08XkYyJCsHEvpb7LdWD2715X9wlvxu/yI/SZ1BD0lX7Au1VJvMTX4HOLcVEyA8IA9 Cyiv5WFN+wybmw/bWVB9BAyzK7Byhvo+vr4HJZxEddXpd7IcEX8D/NcZ0MV21g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1767306110; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=irbJbPpUeLGfNtbC+26lE3WxIkPbtHQfvJ61omAWAbs=; b=vGQrTPf2hoAypQGF4gP81fAy6ISzdvbh2GvETQvS/Ktm0XagsgW4YSExyc3aioO/n24EFJ NEEVF6MHSsyzellL5Srvn0+jI9lexfpb1Fj57+MWMwC6ZViH0OHY5+tRDIR6dr9aZ30jlQ gVKm0ouKPwhKOEIGMgJMcvhFfbS1ZU4+P3XDCd0al/e28QcugxKJvfoUoH+y6c9ruCmPhH zNMVFdLvt15paM2WjSV6l9zHsShdW2+DgaTiPa38PQa9R8U1jMnMRlLv9hR2SDfiX/Idac 4WqSQc3O9OmyUBb1kgnK6ZZn8BeEgKhfTZ8K0N2ZDIPvaj1pMj7XUww1UDjktQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1767306110; a=rsa-sha256; cv=none; b=E9kI0/HvPqDGOziIYZ+6eOtJJgS9LOKpZi4xorhG6JKCzF5brzHbnl2yve/PoNxmSEK3Zt U56Od+UUtKeCisDjviQBI740lha4Tv9vb6ucrL+ReWYHyQahk8GZvBoYaLSPlSdwVE9iMG o0vGiQfTCe+L83Emhdru+TMq4h5I+C5sET695axQZJdfvZOqooLrXPIAekoXkogCO6HKdc aHZLTi47LRT16Wsoh6XaitBMhHuDKxVXl7mesddSd9EbWD/CQ0mXUxxQDULcqYX++dzEBn sL4hxNMuHNAgkEagh17biody3ppSK/1ia6QUlZ9jZOS01tOSFeTVpRwtyNmCwg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dj1Wx6w4Szrm5 for ; Thu, 01 Jan 2026 22:21:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id ebca by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 01 Jan 2026 22:21:49 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Robert Clausecker Subject: git: 54849107681d - stable/15 - libc/tests/string: improve stpncpy() "bounds" unit test List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: fuz X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 54849107681dadaf0aa7bc88d55b7defe3f7826d Auto-Submitted: auto-generated Date: Thu, 01 Jan 2026 22:21:49 +0000 Message-Id: <6956f37d.ebca.43daa179@gitrepo.freebsd.org> The branch stable/15 has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=54849107681dadaf0aa7bc88d55b7defe3f7826d commit 54849107681dadaf0aa7bc88d55b7defe3f7826d Author: Robert Clausecker AuthorDate: 2025-12-04 16:34:59 +0000 Commit: Robert Clausecker CommitDate: 2026-01-01 20:57:33 +0000 libc/tests/string: improve stpncpy() "bounds" unit test The test is extended the same way I previously extended the memccpy() test to fix what is probably the same kind of bug. PR: 291359 Reported by: Collin Funk Reviewed by: ngie Approved by: markj (mentor) Fixes: 6fa9e7d8737548ef93c573387ce62402c368d486 (D42519) See also: 61ed5748e4e9c7397fcb2638b442f46ac5c9e7c5 (D46051) MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D54169 (cherry picked from commit 123c086200491819595abc271d360e605288fd18) (cherry picked from commit 8be8642826099368208efb2c1222f2a102cc5b08) --- lib/libc/tests/string/stpncpy_test.c | 55 +++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/lib/libc/tests/string/stpncpy_test.c b/lib/libc/tests/string/stpncpy_test.c index 8574b2d591be..7fabe17bfe4a 100644 --- a/lib/libc/tests/string/stpncpy_test.c +++ b/lib/libc/tests/string/stpncpy_test.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2009 David Schultz - * Copyright (c) 2023 The FreeBSD Foundation + * Copyright (c) 2023, 2025 The FreeBSD Foundation * All rights reserved. * * Portions of this software were developed by Robert Clausecker @@ -52,34 +52,57 @@ makebuf(size_t len, int guard_at_end) buf = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); assert(buf); if (guard_at_end) { - assert(munmap(buf + alloc_size - page_size, page_size) == 0); + assert(mprotect(buf + alloc_size - page_size, page_size, PROT_NONE) == 0); return (buf + alloc_size - page_size - len); } else { - assert(munmap(buf, page_size) == 0); + assert(mprotect(buf, page_size, PROT_NONE) == 0); return (buf + page_size); } } static void -test_stpncpy(const char *s) +freebuf(char *buf, size_t len, int guard_at_end) { - char *src, *dst; - size_t size, len, bufsize, x; + size_t alloc_size, page_size; + + page_size = getpagesize(); + alloc_size = roundup2(len, page_size) + page_size; + + if (guard_at_end) + munmap(buf + len + page_size - alloc_size, alloc_size); + else + munmap(buf - page_size, alloc_size); +} + +static void +test_stpncpy(const char *s, size_t size) +{ + char *src, *dst, *expected; + size_t bufsize, x; int i, j; - size = strlen(s) + 1; for (i = 0; i <= 1; i++) { for (j = 0; j <= 1; j++) { - for (bufsize = 0; bufsize <= size + 10; bufsize++) { - src = makebuf(size, i); - memcpy(src, s, size); + for (bufsize = 0; bufsize <= size + 32; bufsize++) { dst = makebuf(bufsize, j); + if (bufsize < size) { + src = makebuf(bufsize, i); + memcpy(src, s, bufsize); + expected = dst + bufsize; + } else { + src = makebuf(size, i); + memcpy(src, s, size); + expected = dst + size - 1; + } + memset(dst, 'X', bufsize); - len = (bufsize < size) ? bufsize : size - 1; - assert(stpncpy_fn(dst, src, bufsize) == dst+len); - assert(memcmp(src, dst, len) == 0); - for (x = len; x < bufsize; x++) + assert(stpncpy_fn(dst, src, bufsize) == expected); + assert(memcmp(src, dst, MIN(bufsize, size)) == 0); + for (x = size; x < bufsize; x++) assert(dst[x] == '\0'); + + freebuf(dst, bufsize, j); + freebuf(src, MIN(bufsize, size), i); } } } @@ -140,12 +163,12 @@ ATF_TC_WITHOUT_HEAD(bounds); ATF_TC_BODY(bounds, tc) { size_t i; - char buf[64+1]; + char buf[64]; for (i = 0; i < sizeof(buf) - 1; i++) { buf[i] = ' ' + i; buf[i+1] = '\0'; - test_stpncpy(buf); + test_stpncpy(buf, i + 2); } }