From nobody Thu Apr 23 13:49:07 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 4g1crh23Wmz6ZllJ for ; Thu, 23 Apr 2026 13:49:08 +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" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g1crh04Sdz3Wd5 for ; Thu, 23 Apr 2026 13:49:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776952148; 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=E8ZA0wqVjCj8ZaKsZEQdEumHmqHL9LNdkRoLgweA9rE=; b=K1AElheYFFqrRMA+nfqjF1EH/f/jEfL5qQyDX2QgGbtRHMP2TVO5rR9CIyh3vGK9leJAUt BVslPdn1Ki5tE5iFC1u1JCajzOV8anmxhIp8VB6SZrwG+kWNFwVt/8NPQZ1Qp7hTaO+atv SYtxmNcxgcQmscr2MGIsHYTE4QF/1XDV7YVNKUXMbetoTwb+dA4mFhC9VLR7lUP5PFEjKz wq9yInvDhKurIJFkJKQ5Az6R1YHb3rGecurDOFdEeg8t40IU1v4FGpcZ6JRDhyg0QiH0dw dl92JYjj9E37HOb04FOITzA9Anj3uX6krapNCbT/cbCsNrM+fAA1LQg3EiNF4A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776952148; a=rsa-sha256; cv=none; b=hgTLgllWU8GcGVVGeZX+8dNZBfZVe9SYPr/MrEXOAo1bLz5IpzP7HTy5nq5Og0iax+16I4 or1yn0OMW57rSQWoljcfa15IRim6m55JpAupMG02urvvAt9Za3cKu+EZ+UYQ1MP7peollO IYkSgu4kv+vks78iPT1IHLHeRhcuQr5r6ewSdB77a6hcSdX9iT6o7pbUOhrJ/p3C9nfDyC fQvNuKRLTUPkSRjrheb2GQwHNFqLKugBTA+ZpH5XHmo3OAty2jFKhs2d6mxkrKzfLcQtvZ 5DGtn6aKjhuv0u17OyMeTRaionfjv1mrJ5SoPmFej7L6SGyyPS9Emf14kqJi+w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776952148; 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=E8ZA0wqVjCj8ZaKsZEQdEumHmqHL9LNdkRoLgweA9rE=; b=rtKiXEtE++kxToB4cWP5N30iFCy8jykKAbMqu0OpOIraySIpr/3CAXu+OLdEC5sapf/Z2+ K8VYGiCuLx+HQLAYSlr+2YHIAkROtZaoy7yoo8vBUZtq/GbGQ7CYnpAbSPVMUgzRXT7yLL KOaQwOR4coDiunO/JIp3PSgp1H8FkU5giyqA2WZwTzNm+BaXUbPchRidDIrIffUo1hXkx7 fWn56kbUEBU2kauqQrIJqi9UNh8+p05E15A9iV1V7EwDFc10h7+QLS1wMMajn4OwRoJs04 o4XO4fss021XG+iZykG3xbwD8wICpmC3RscJCebVKSsILa4OtH0ruuoAuxPtAg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g1crg5v9Xz3s7 for ; Thu, 23 Apr 2026 13:49:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 21cf8 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 23 Apr 2026 13:49:07 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: f3c488fc6b9e - stable/15 - libutil: avoid an out-of-bounds read in trimdomain(3) 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: f3c488fc6b9e7af298c44946dc867652e160a8c9 Auto-Submitted: auto-generated Date: Thu, 23 Apr 2026 13:49:07 +0000 Message-Id: <69ea2353.21cf8.62503e1f@gitrepo.freebsd.org> The branch stable/15 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=f3c488fc6b9e7af298c44946dc867652e160a8c9 commit f3c488fc6b9e7af298c44946dc867652e160a8c9 Author: Kyle Evans AuthorDate: 2026-03-03 22:51:02 +0000 Commit: Kyle Evans CommitDate: 2026-04-23 13:48:43 +0000 libutil: avoid an out-of-bounds read in trimdomain(3) memchr(3) will happily believe we've passed in a valid object, but hostsize could easily exceed the bounds of fullhost. Clamp it down to the string size to be safe and avoid UB. This plugs a potential overread noted in the compat shim that was just added. Reviewed by: des Sponsored by: Klara, Inc. (cherry picked from commit f268f95955f5f0f91f4d39e13bcd69a24e0d8ce4) --- lib/libutil/tests/trimdomain_test.c | 4 +++- lib/libutil/trimdomain.c | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/libutil/tests/trimdomain_test.c b/lib/libutil/tests/trimdomain_test.c index ad5b92b0ce1e..c6305fa72ae9 100644 --- a/lib/libutil/tests/trimdomain_test.c +++ b/lib/libutil/tests/trimdomain_test.c @@ -78,11 +78,13 @@ int main(void) { - printf("1..5\n"); + printf("1..6\n"); testit(TESTFQDN, -1, TESTHOST, "self"); testit("XXX" TESTDOMAIN, -1, "XXX", "different host, same domain"); testit("XXX" TESTDOMAIN, 1, NULL, "short hostsize"); + testit("XXX" TESTDOMAIN, strlen(TESTDOMAIN) + 256, "XXX", + "long hostsize"); testit("bogus.example.net", -1, NULL, "arbitrary host"); testit("XXX." TESTFQDN, -1, NULL, "domain is local hostname"); diff --git a/lib/libutil/trimdomain.c b/lib/libutil/trimdomain.c index 47297817a76f..a4d53deaa216 100644 --- a/lib/libutil/trimdomain.c +++ b/lib/libutil/trimdomain.c @@ -73,6 +73,12 @@ trimdomain(char *fullhost, size_t hostsize) if (domain[0] == '\0') return; + /* + * Clamp hostsize down if it's out-of-bounds of fullhost, to avoid any + * kind of out-of-bounds read in the below memchr(). + */ + hostsize = strnlen(fullhost, hostsize); + s = fullhost; end = s + hostsize + 1; if ((s = memchr(s, '.', (size_t)(end - s))) != NULL) {