From nobody Mon Oct 20 16:11:57 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 4cr0mt3XQ8z6CgnV; Mon, 20 Oct 2025 16:11:58 +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 4cr0mt0gRCz3VtK; Mon, 20 Oct 2025 16:11:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1760976718; 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=4wB6+Fu7LnbS+PPmpBjXFLjRQQAQppjWbbadywAky+w=; b=COa7S5Blz9pJq9byqmwWF0K6vxyFicWm4XwlOQ4BKmzi3Y1m4yOqjDe1fYebOgra3v3Iyo nlVAgo/8gXtfV0bVUfmUfO0ehw3MFpMZNh/P7a6ZPXylYRQqio/+N1FQtbn6AglMF+3Pi1 GWWZ/t3bp0sbNJcWdNf9tMLRY2PU+BkXZOS1ZAFLpLp6XuLfUAtpGOM05dUtI4sZtolIzl +U44wqivQl9nduA2fR/sWHW9ZBhy1Se0AgVAlVZNSIz3sAquBuQ9WTzUeyHpA8kQCO48Qm fcJA2tXrgGtJyFc9NffAo/nLsShc9H+GSgOVpRS0WogQuT2l1FOxM4eU9XBmtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1760976718; 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=4wB6+Fu7LnbS+PPmpBjXFLjRQQAQppjWbbadywAky+w=; b=B42qWAthlGVkUtlt/UFJ6U/WpthSselS/C+BljT/alHhN/2e1f7sjWj9hgyW1z+V1sdJNz UbxS7WcRu6qnOkUi5He+608uZtXAKyIgNuLewvV4V19XQDZ2VdHHOuzuncftVD9cBrTTt/ IWPZyTuJSh7RNXDJTuavGc3yRYNwbkrhNQBoruuFBH3gkx3a9F3bk4pZPLA/zKOPf/gW3n 2LE3eFBa1k3hVHfClV3luzqwV8hMxxHqdVzKOigkSzhzJ/ZPyZH1WiEp67RKsUBzvb5GNS zoyocf2aKCL6O8xruuo0RmsE8i9MZ71UPPoDA7E5tnsmcDuFlShQu+23EakFpA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1760976718; a=rsa-sha256; cv=none; b=NegnjVhGRXKuQ7e0pIUwWbaqHtzkILSNp7LVGME8NrVoue529ZgRYw5c6XX4YI6ThJHAua 4s4tl9l6UY59eaaDLtCYDSjqc9i2M3pdki7cI7UqDJh4RSF/tvNEfDfR7dkKwQ5ytPesWf SYBORaO+UHNi8++oYzbsARKmOlb7gd0qn9hpwr0/TAlWyNJ5zFmABGQ49E0IDWTxCo4OMQ 6Q1pWQDO/keRgKDOjrniUY1WYkM8gCRMFDqwirzUcr+Q9JCA5mFbzAGd0X4dHWloA+R84X 2VlKXFmrEzMTNjFtWw4nyL8ffmkAvQSXiluuVdqiir0RAYl1ScKK/GKdriglwA== 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 4cr0mt0DBLz4Jp; Mon, 20 Oct 2025 16:11:58 +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 59KGBv7k041597; Mon, 20 Oct 2025 16:11:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 59KGBvPj041594; Mon, 20 Oct 2025 16:11:57 GMT (envelope-from git) Date: Mon, 20 Oct 2025 16:11:57 GMT Message-Id: <202510201611.59KGBvPj041594@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: bbf986d0f140 - stable/13 - 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: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: bbf986d0f140d847b9e0c808bf6006b62e85e78e Auto-Submitted: auto-generated The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=bbf986d0f140d847b9e0c808bf6006b62e85e78e commit bbf986d0f140d847b9e0c808bf6006b62e85e78e Author: Dag-Erling Smørgrav AuthorDate: 2025-10-17 11:54:48 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2025-10-20 16:11:48 +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(). 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) --- 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 037db7ba3f55..7042acf07bc4 100644 --- a/usr.sbin/quot/quot.c +++ b/usr.sbin/quot/quot.c @@ -281,14 +281,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");