From nobody Sun Jan 4 13:27:29 2026 X-Original-To: dev-commits-src-branches@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 4dkdX140VNz6N23H for ; Sun, 04 Jan 2026 13:27:29 +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 4dkdX12BTBz3P6V for ; Sun, 04 Jan 2026 13:27:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1767533249; 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=vAVjOpuCghMIoh2wbKytJRKd3TGE7SkZoIQNcgGgzQU=; b=A9hR6rPrWPEKh2nAK1+/4mmUKJmFpFA9kXtlK4TyvK51foJK6zH4OQFILCv6b42/8NRX+M THO6zYTfuhMptpglFiinrN/+0xkYbe01VR13HzEFm+F318nxJFuQGcA4baHq7xMzYFRJUw TlizPqdQSgx6lD8T1qVmnoAkZFuoCgKHQ2MNQ1c9BFkn5Hi6HLZFhHHuDJvTf9t4mY/2JU v2+Fh9UWrfWAIFkJmxS5GqVuQHzK+Yal0xqLigYSTIvuTa1pIq/ZywTrHDZxKt/G6R2VIB qCpddAygDK0ngdg8Hs5J7/0jshIZl63AwZV1LCmJ19vR6o1anxM/Zjc4Nwudug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1767533249; 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=vAVjOpuCghMIoh2wbKytJRKd3TGE7SkZoIQNcgGgzQU=; b=wmBEjOe5UT4463mcGdeEhJOKFTo+MXeo7rM8FSPLsfYzH4iLs9k9n/lGqMcC4RE9YHA+jT jUz3fuNug8oKyJne/RokIc8D4KMHj6qoE6ra0sTaOpzIvvTQ4aifrhSKVsEFMYHNL+5HdL WClLNPzWxYqit2OYPKSqbqOGdYDyhVa3LHESxvUDcpKIzKlceqUGpatfpq10HKyUAnPMJ+ 5YveGd3qwZUYe+rwp1cpWPswYQDZDwYwVD+wM+VuZYTmYfY/swzQxcXbcGZXX/QyE4Geyh zYzeDlptC9hIbWTgt0v32OZAKCqK6AIcvz8z9U6X7wUUivW+D+k4r4y1dclNFA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1767533249; a=rsa-sha256; cv=none; b=cninMv8ubZWI7HuGQcdo71O5uu9f7NoJ7ugFwq6lWHsneivWhzDKBDQyhrL/mRW0Z/3+qU jC9wqpfZEOTPKogeHiqbRi/70DIdGpev4fTSod8s77c9ACX4zJhtefLl0K/WMzR5a1nvzJ GY+bq2QqKhycYidk+UX9LnGIyjUJUi1mKDQsm7rvuCLVoZzAlg4wn5KtyiAl93NyrkU2z9 kTYfD+HdxBXDLMzigr9NllwogLiO4ZjN0qCunn2h5l+oi9UKthZXZ6gLMe24ZeTEvmcu/P X0m6j1/VVdd5mtCM/bExMPhNvdGIL9Tx/9EnjvuF2SvULvidZIZUYk9d2agpOg== 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 4dkdX10xh1zd3f for ; Sun, 04 Jan 2026 13:27:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3af68 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 04 Jan 2026 13:27:29 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Robert Clausecker Subject: git: e2f095779323 - stable/14 - libc/tests/string: improve stpncpy() "bounds" unit test List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/14 X-Git-Reftype: branch X-Git-Commit: e2f095779323204e90843b405863c81dc02423d2 Auto-Submitted: auto-generated Date: Sun, 04 Jan 2026 13:27:29 +0000 Message-Id: <695a6ac1.3af68.37e5642f@gitrepo.freebsd.org> The branch stable/14 has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=e2f095779323204e90843b405863c81dc02423d2 commit e2f095779323204e90843b405863c81dc02423d2 Author: Robert Clausecker AuthorDate: 2025-12-04 16:34:59 +0000 Commit: Robert Clausecker CommitDate: 2026-01-04 13:25:21 +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 lib/libc/tests/string/stpncpy_test.c: apply ngie's fixes (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); } }