From nobody Thu Apr 23 13:49:07 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 4g1crh23nyz6Zlhs 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 4g1crg6HFKz3WxP for ; Thu, 23 Apr 2026 13:49:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776952147; 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=MeXsTf1E63pPvGvbVvwnAMQCEm02kqjpgmv4b015bqSo3NZydYg0EwPZnG+OhWeQ6NVXxH OAUhTcu8npSLMjdiGCboo9ugXcgiQHHYeH4gy9+V1JhQZxIGya/0myDXtjL+p90uudOy8m G3ouDMPjgHMjhdt6cEOZ5UMDmJ55pAK+iWYpxkH/yoxxGCbwOFbyI/9oLUnLxIAP8z9MFk Csc8TBXMLu1+FW4s+6UGA7SbrhIgc4i2AAUfZMzbKKrvMXllzJsjpzyNgZyH5Xj/GoEFcc Hv6+J+bEBNqH7/et15JFDXQo2x9za0KMIiML5y/kQTI1Rqw5gAlmFQMhTTaOgA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776952147; a=rsa-sha256; cv=none; b=R0oSQwbLUKGwtuJVWf4kxdgmi0M3aej5zP2WJtn8Yrmvmk0cX9fs3hlKsKLQ8x4XNY42OS 3jranVn8rBQaHIuF1nmUWtKLiy9DnTc9GhHFmPjY8w7z/oLfbOLVhW2rPs3ff1FviU9Z8N 1lItTuTrLD75UVp6O/B5lg6Xvi5eC6JP5WeYSJPtP2JvG056tvewKRGQuTQl3VhgLPI3HX OT9NZqYBZOOBQ9PXK5kWS4QhrdbirAISaMjKQ4h22kquuMea7it+OCxmGhIBJm1vQF/jBo BbXZkM9bBK3KBAcrTxGVfTxEB+UvkjDtg8/zF5KWKHWyva45acH1Ua7rI3IiYg== 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=1776952147; 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=k7/WHuibm88M182RIJ+3OXJaxpkrj1JlwjN9NeWUHGUL0ftOOiR9nKjjAY2trFh2QRrsBu EJz1bT7q0NEKqrpKXTRMWrXhsMxmGeymlfJsUi4vuhqLDsadxjHljCsGTnIIt9A39BjnTi VFUZTY5jDgG8brX/wHQHTccyt1tdbY85tloRb5dOjb7Cv57tasnE6/o4tDYm5hEkBwXDY+ 8UrwFLYJUUyyj2jnqdMJP7YEpYCUqAZjdvANvinvbNJ7ZHGRqHn3cFOQZ3/XblEzNRZ/IY d4m24BHrK8zj5dQmnLkzi9sTTLlEHswuMCsKll6k2+belImzgP+WKAjqKZA4Tg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g1crg5rb7z4BB 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: 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: 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) {