From nobody Thu Nov 19 17:10:15 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 4jVlMq1yPbz71Snv for ; Thu, 19 Nov 2026 17:10:15 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jVlMq1V2bz4Ln8 for ; Thu, 19 Nov 2026 17:10:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795108215; 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=C+39EmyMDI1Jf89DOI8KSMwvHcCwifLb9tYO+mLJtn8=; b=OBPU6qrOb3PrRdK+csjoNj7RccR7BtVQce77MmigwYaryP6zr2+4wQBWaiIoaX+kvEigPc ya9QSdPhVsqHWXVlh4aMoDY5s7aWdfvs8wbXslxO891alaIWGfLU6sD/XZQMtrAMYlE4Gd GmawcuqmC9h5MTPbD5SvVCc3BnAfsDooWQuCv+zROnHKXJNxMM5EjxoC11ZLH1niDf/0Q7 CzQOJhgROLryE6NAZIA34K4fo3pnKLGXZR6HGsi7B5fW5Mu0oHnZw6WtRpJHrmAoG2bhEA RzzU8/53I6egnlcwbPKqmPtfZ/sFPWr43XQTPhk4Aq28a3GWBvZ/J/qRCJgXEg== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1795108215; b=PmpEbfiYxWfhTu5BueG6RyinLr+iUsT0UH7JmF4mHdVKB6yes4yz339LJ61qRKKMKIeDjB fscbReou5+CYnz0bGjYUCbo4sNIDx4TMaYLj7zpszb0w3BYfXRsE9S8Rqra270DJWzbbWI e2/Ys0znqIDH85G5a4ssI/JER2kZpeD1kTvCqAOEbSpa8NDZejg5FxP26l6B/YCLZ0/8WP ps/zw1wh3Xz4uphfJDFTsl4C1ETOi3aitNgI6VZrrcZM1+Al3hQZIUmM+qS4ZmkBxWBHbi g/wkvhV9mTtghdRyCEpED7ctf9M7nlQi1YtW+s0XYC1lw4bjmuaRQ298ViAwxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795108215; 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=C+39EmyMDI1Jf89DOI8KSMwvHcCwifLb9tYO+mLJtn8=; b=ykmouNGkCAfxe4byaT2G00xILacjP69bGZT0cqsO3+Oys0V3e9nqPqZXQx7wg0WU6J2GWR 6UDGmOK/riDcz9TsfGcpvkOOM+ZVbFKcViFYHK+uQp1owHWSvG2kDROZAEG9o/xBXNdCs8 v1ylArl6KpV67iTVm4o3uWf4bVYKB08OpLBXH+1fXpIQYVb7YrnqTdGKSuS3CpMfzf+4YL 63EDJSW8mu7W+8Wsn4O6i9P3mM31cwoWbz9EmmEEnAyInNlQSJoORLOBa2fOhBvT/zxZx8 1hLeRXC+0eNs2EakVzqlw8DZUJy99Cwf4qUPx/EWRivfsf0Tha4SXYfZRpKgxQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jVlMq0b3Yz1924 for ; Thu, 19 Nov 2026 17:10:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 13ef5 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 19 Nov 2026 17:10:15 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Roman Bogorodskiy Subject: git: 78a69f98b104 - stable/14 - top: fix off-by-one in screenbuf List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: novel X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 78a69f98b10425c946fa67ed4b916c78e33d6852 Auto-Submitted: auto-generated Date: Thu, 19 Nov 2026 17:10:15 +0000 Message-Id: <6aff2d77.13ef5.be93028@gitrepo.freebsd.org> The branch stable/14 has been updated by novel: URL: https://cgit.FreeBSD.org/src/commit/?id=78a69f98b10425c946fa67ed4b916c78e33d6852 commit 78a69f98b10425c946fa67ed4b916c78e33d6852 Author: Roman Bogorodskiy AuthorDate: 2026-11-15 09:19:44 +0000 Commit: Roman Bogorodskiy CommitDate: 2026-11-19 17:08:05 +0000 top: fix off-by-one in screenbuf There is a heap overflow for screenbuf originating from the top import to the tree. The i_process()/u_process() functions write a terminating NUL one byte past each screenbuf line slot when the line fills the slot, which is a 1-byte heap overflow on the last slot. The display_resize() function allocates screen_width bytes per line. i_process() and u_process() cut lines to screen_width characters and then stpcpy() them into the slot, which writes screen_width + 1 bytes. line_update() can do the same with *old = ch. For inner slots, the NUL lands in byte 0 of the next slot. This can corrupt the saved contents used when updating the next line. For the last slot, it writes one byte past the end of screenbuf. Fix by allocating (screen_width + 1) bytes per line and updating the line offsets to fit the terminating NUL. Reviewed by: kib Reported by: llm-postcr MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D61593 (cherry picked from commit 5233aaccdce59abfb80312cdbe94495516fd211f) --- usr.bin/top/display.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c index 32b8b12798dc..85105853a169 100644 --- a/usr.bin/top/display.c +++ b/usr.bin/top/display.c @@ -57,7 +57,7 @@ static int lmpid = 0; static int last_hi = 0; /* used in u_process and u_endscreen */ static int lastline = 0; -#define lineindex(l) ((l)*screen_width) +#define lineindex(l) ((l)*(screen_width + 1)) /* things initialized by display_init and used thruout */ @@ -140,8 +140,8 @@ display_resize(void) if (lines < 0) lines = 0; - /* now, allocate space for the screen buffer */ - screenbuf = calloc(lines, screen_width); + /* allocate space for each line, including its terminating NUL */ + screenbuf = calloc(lines, screen_width + 1); if (screenbuf == NULL) { /* oops! */