From nobody Thu Oct 30 23:52:30 2025 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 4cyLWg6Xbgz6FnNY; Thu, 30 Oct 2025 23:52:31 +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 4cyLWg23gCz3cdx; Thu, 30 Oct 2025 23:52:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761868351; 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=ZY7hYA2uBmMu5iKMT+TN9uTTc996kG9z203zZiJ6fqg=; b=PHErWBfpECd/bg5A7E7/TW2gcBxnVV9yd20TnA63hGOMjPMWuDvwxPKDh7ZB9EasN8dgRr 6jX57U/yfzYpZDW5x7UXBptJNWcTkv3PqK0GnY1JFkD1LY0atZgSQn27X8wUmwaKp2Swql AgDKpvenP0oUZvBYqh7rpNGiUN/9UN16YioEa0NPyfL42tn0AIvVONDoucAqQEps3DMP6D A+PjQaNAaeDBrFUyXnMDyGjSQhre6H3XupzjsSA4CfFwnMSusVOOUsKXzRIG65YdXCZFjB WH/w+Q2S35AZJYbSbov0yWGUr+cmoNADCo0D/8ylssfjnvKSs4k85Ov86vZu3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761868351; 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=ZY7hYA2uBmMu5iKMT+TN9uTTc996kG9z203zZiJ6fqg=; b=u3pd/NPocnHGYRALqqQlM6niy8I1YDvxBUBBgL39rT1RsvKY7qmpdYJj744p4Nwtg8Fqud XNjjFpKHEeYjhC5AstS6AUT6rCKQ1gEhtPshp7qo8IG2QDasJZnvDVV6VbnzzlxjosZAd/ Y0wIubbxhAaFpoNJte1HzEVeNuK7BOqzPe/cbh0NeMxBYz9qFLH3dcMyLRI6v1CEXcoKAs o3WuFEoBbjjll+tOPF3b1yn1Bvk9rvy6SbtiRVaUVuQFQKrqplwVdAa4Xc3dqPDIal2rQu Shb2ulbm7p4Nthncu5ujnsfSJCyPxo+JWmUCrRmj3ixsx2pZF7cIBuSpHnfkig== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1761868351; a=rsa-sha256; cv=none; b=uPgilLCrSKECT0/lNJ5Lmxl7gM0tdpM0ypQLlAQ36Ge9HtBoWvQuR6eDYmY+YjvlkmS7nM CZj3JMGjSOdtrf9PTfMIfO1t6EpKN0M3JEuz+otmKWhD7xPL2uB5o+mNfRTofy4z4A8uQL cDrbuk/1lJIlcQLIHv/plSaI5G++Hei5oc62Ol57YtmcwotsmyMImMTVXHuJPaRJn2fFjb j7vLlvAnOmrYQSvfvgPa8dF3w9XeeO20m15RcBFhnrrtfeDZm/7UyUyTmIHm5XIQE/niz3 fT9IutS6JWrg9hfcykwTm11k2lOzhYCKrLHAltyNXOaXkxNduXk9QslHJP3W0w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cyLWf4KhHzlXw; Thu, 30 Oct 2025 23:52:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 59UNqUTM088226; Thu, 30 Oct 2025 23:52:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 59UNqUV4088223; Thu, 30 Oct 2025 23:52:30 GMT (envelope-from git) Date: Thu, 30 Oct 2025 23:52:30 GMT Message-Id: <202510302352.59UNqUV4088223@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Colin Percival Subject: git: 60384327a89e - releng/15.0 - quot: Fix benign buffer overflow 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: cperciva X-Git-Repository: src X-Git-Refname: refs/heads/releng/15.0 X-Git-Reftype: branch X-Git-Commit: 60384327a89edcc35bb9e903633d26f91403860d Auto-Submitted: auto-generated The branch releng/15.0 has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=60384327a89edcc35bb9e903633d26f91403860d commit 60384327a89edcc35bb9e903633d26f91403860d Author: Dag-Erling Smørgrav AuthorDate: 2025-10-17 11:54:48 +0000 Commit: Colin Percival CommitDate: 2025-10-30 23:48:31 +0000 quot: Fix benign buffer overflow If it encounters an inode whose owner does not have a pw entry, quot allocates a 7-byte buffer (8 in practice, since that is the minimum allocation size) and uses it to store the numeric uid preceded by a hash character. This will overflow the allocated buffer if the UID exceeds 6 decimal digits. Avoid this by using asprintf() instead. While here, simplify the common case as well using strdup(). Approved by: re (cperciva) Reported by: Igor Gabriel Sousa e Souza MFC after: 3 days Reviewed by: obiwac, emaste Differential Revision: https://reviews.freebsd.org/D53129 (cherry picked from commit 5854d1cbab1073d78519e7ad9a6eb5726341d587) (cherry picked from commit 3d680881f6ed2f55079aac26cf0ded307c282563) --- usr.sbin/quot/quot.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/usr.sbin/quot/quot.c b/usr.sbin/quot/quot.c index 4152c498371a..c11c46a500a1 100644 --- a/usr.sbin/quot/quot.c +++ b/usr.sbin/quot/quot.c @@ -280,14 +280,10 @@ user(uid_t uid) usr--) { if (!usr->name) { usr->uid = uid; - if (!(pwd = getpwuid(uid))) { - if ((usr->name = (char *)malloc(7))) - sprintf(usr->name,"#%d",uid); + asprintf(&usr->name, "#%u", uid); } else { - if ((usr->name = (char *) - malloc(strlen(pwd->pw_name) + 1))) - strcpy(usr->name,pwd->pw_name); + usr->name = strdup(pwd->pw_name); } if (!usr->name) errx(1, "allocate users");