From nobody Sun Dec 14 16:08:16 2025 X-Original-To: dev-commits-src-main@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 4dTp5D445rz6KQj0 for ; Sun, 14 Dec 2025 16:08:16 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dTp5D2WsBz44gv for ; Sun, 14 Dec 2025 16:08:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765728496; 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=WLd2XQCqWrnhjIt6437VfAW55OPwOUBhVPCdn85q1Rw=; b=nlYu1Dyxa1nSR0uyUric0O4wbSS6lRXbcSg2bEkT4RXE67TmSUF1lRvAlQg9V3XJyO6lfA hiQ3Cov0V9AsAAySaY7lmXTeGAA3LAafTe/tkb1ES7teKkT/E1vaJh16thpGYKeRcgHlh9 BujaAcUieGhUiVr4pEmc4HGx3NUwRXHdXoYBHqwb98bib4fwFlVesqn+DB9wlD9gPdNeZS R2A/A5Wib5Of0vMW31SrmGBuUXCDzVA6iPtx0/lfE5IXhPCN8VA/nfcfv+gB8YHKfhJTbl kMeJIRCwkT3DMPFUuXLpcIVvJ6obaPIdhxLj81Kxixq7tG7dD80C0UsjPOAoOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765728496; 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=WLd2XQCqWrnhjIt6437VfAW55OPwOUBhVPCdn85q1Rw=; b=juhoZOmADH2sGfOwWbPJ4/6GcHg1AfPjdB/5Ok28g9qqZxlAZzQBNF5YjgLnPU5GNhfZJM mYxCwZNZNRtS1YPlCwjwEnzsWP/2DHo12KryIf3/8IRpPss5+LHv6rIiErNjJsPnII4Mfm yjE4mDiRU1KlGzj4AAR3oDsaBz8i4zqacYweZJtxFqhXOIBL4X2y+upKpuP6BevAnfEeuH +FcopKkc2MMsaqV/dfLQ28wQoV0c/QuNXxVBHBHgyTtQGES7cIHWpe1EbDwVT+Hc4kJ/NI up96m4PpM9v1P70uEhywwc+oEQLhkIjLhx8XYgRuNxYQ+X+e6y3NyeZj/VjM1A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1765728496; a=rsa-sha256; cv=none; b=dMidctle20wyR/BgIphiZFnEf5S2CBBnipbVQteMJvB9QhvM5aQKa6XVNwhRwaqJWF4cD4 o7PBfVezU9bOF93Dgaci0fgNLR0S98PlinvPPoACyomW/FbXzufDgTJjm53ZamZQxLFxNz JUFXRaO/tevbYWk9/Iz+2kpwxII7tnrFfeKxVNaWJ/rsskGcWCYebhWrMlx1bk6T5PKwdD wbvNGdG7EeMW//ic8FEabG05HXWKLb7PsYpNKzCPdRVW2Br8tmiKBKo9pemLGYeLEbkliH FS7Hig1oOSxhqS+xGSl0edmLya5ihvXYMZGHUj+QTWZGgFYBQjj3zruQ9RLTWQ== 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 4dTp5D1c0bzgqW for ; Sun, 14 Dec 2025 16:08:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 36305 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 14 Dec 2025 16:08:16 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Robert Clausecker Subject: git: 123c08620049 - main - libc/tests/string: improve stpncpy() "bounds" unit test List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 123c086200491819595abc271d360e605288fd18 Auto-Submitted: auto-generated Date: Sun, 14 Dec 2025 16:08:16 +0000 Message-Id: <693ee0f0.36305.6925ea64@gitrepo.freebsd.org> The branch main has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=123c086200491819595abc271d360e605288fd18 commit 123c086200491819595abc271d360e605288fd18 Author: Robert Clausecker AuthorDate: 2025-12-04 16:34:59 +0000 Commit: Robert Clausecker CommitDate: 2025-12-14 16:05:30 +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 --- 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..2dfd932d45dc 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)); } } } @@ -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); } }