From nobody Tue Mar 3 22:51:13 2026 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 4fQWHj3jPWz6TlGm for ; Tue, 03 Mar 2026 22:51:13 +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" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fQWHj0zmDz42B6 for ; Tue, 03 Mar 2026 22:51:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1772578273; 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=UAFh0UIuiiboLFQYC2loMqxE3e7lIte99DVUgoDdIC8=; b=miDNN1dwftKakuJwNLY3i6QeRWplNP+YQ5LPy9CEbublEA2C4fUF3Vz297Stv4W6dxtZol p9Ds95s3saBKrN3+v4Ns8WM8oCWtHck+RUdmHxWDUzIcx9G0208x9Ll1nVOSEWB2z5v2Mp k+UzxejqdTWIGhD84H5nbrSr7VxV98jSCwkiqJe79IEzVavpMae82khyKQZ7RwFOyS/hef MHGnBjXekdmQFdWgS0MlR2ku4PqnD3/uSD5ieptMAyNZirazPleAx/PIXomOLPMF4DJIO8 yTpkX5znN6+gvaapaeBzpXnJOgc6SFn8bH1BPe16+TJJCHHCH9nuuxwJlDku/w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1772578273; a=rsa-sha256; cv=none; b=GeVDYdNeeuUVKaXJeGCQYqlFbnPvQzgsSLh7pAGVyNtDlyeM85/zRncf9hc6WNC8Mmgm+V zNjbgQgYjAu6jvxlFDLsiMThaC5kdcWKcMesCRtTljtTZr6wLjoEh/Ykd4ZTyJTlC0r7hN yOQ1jFqxas0wLVnjLNuBC5+v+MOf514SjliprDnQwSlNTzT2yEjjrA2TR/QvwrY71T9Fkz R6RpS1Jq0NxLBo1ZFB4dX6ZdRC7vewJYtX0LAQRGiS+L3bahd8yg+JGn4cEpEXz+iRx2Fo fA+7bg9JiUdC6E0L2ZSpvdFgrYnNLw5Wwxdo0swuPWwMpXUiDF67HE5qkujG2w== 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=1772578273; 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=UAFh0UIuiiboLFQYC2loMqxE3e7lIte99DVUgoDdIC8=; b=WTJzXZbVScBNbWWffSi6AFtHAqDWSMCivbOSnJHCN3fuzIIy8G3C598i2izzrKNleBbxKp vQiwDEXENLZf2dIYD2Vglx92yYGd8BVtJ6/bbyIB7+Ic3rLt3C7lCjGLqPKicUM5frtUcA zrIn3eyHvFBqsbTAsb5AtRPbxFY8FsIXCJRuqavpMLJj6SNDXp1F+iP9OfRGbADi5HZCHc FiRXVIdwenkC7Wmy2y94QGaZIB/cXdQDRILb7+W2wZEPgzxZfWHUqa02wXKOv5nRz5abXB iaRpUN7I0SaN47L7jccW2yglSGV+lI6FHs/GRa0XuCSBgkyy5vv5D0l+Zn+Lpw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fQWHj0DBCz8fW for ; Tue, 03 Mar 2026 22:51:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 39c57 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 03 Mar 2026 22:51:13 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: f268f95955f5 - main - libutil: avoid an out-of-bounds read in trimdomain(3) 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f268f95955f5f0f91f4d39e13bcd69a24e0d8ce4 Auto-Submitted: auto-generated Date: Tue, 03 Mar 2026 22:51:13 +0000 Message-Id: <69a765e1.39c57.10364b9c@gitrepo.freebsd.org> The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=f268f95955f5f0f91f4d39e13bcd69a24e0d8ce4 commit f268f95955f5f0f91f4d39e13bcd69a24e0d8ce4 Author: Kyle Evans AuthorDate: 2026-03-03 22:51:02 +0000 Commit: Kyle Evans CommitDate: 2026-03-03 22:51:02 +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. Differential Revision: https://reviews.freebsd.org/D54623 --- 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) {