From nobody Mon Nov 16 09:46:47 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 4jSjgW5SQpz71fP5 for ; Mon, 16 Nov 2026 09:46:47 +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 4jSjgW4zQgz4dVJ for ; Mon, 16 Nov 2026 09:46:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794822407; 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=lm+KhAiLnB3Q1wy4bOYw9drVUBnS7YyxEg9RaSAeHmY=; b=xbbvrP/Bgmh/wY5IxiVj6AZZeQDe7CglcsGl06/iKPwiL/V6bnQbS1pT6Mv0jYEIPbkzqx f8bZzw7k05E+IG81KF8IFrujCjouWx3RZpciv9DZUgT8v1/tuc0jAQ0J57EKCLdA8gBeTN wx961MKC9D2ICRipRNYVf0FWQg56Rv/4sUVi78IpQEnF9auZh4AJU9R4QErq4Aye0aPiCa YBbV5LSr1Cg/YXREYGpufzuarZ0uzV06VdbYBiB6XYqy8sMwPsfB3O1bivqTUVmgajE/f+ iDCOkC02VPoYPstdktDj+Qf5pIX5F5JjvOc/wCVYXWR8tcncHDUp46FRI1HCOw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794822407; b=YPMOsq3THIR3/8VaGdnp6MwDerwd0wZ4kr+UgctX31K66kUzLtN12eawejQkbzls3yNCf3 1KV1Jcj+tgTQrZHe7rwBiG8Yx/MEMISRJ+jQW52a2Ngy+z1VmTYkeX6QGqjdW++wK3ER4y B9md5vSPg4AWh+Xc7r4W0rDpTi5Ntla0mwavryC7bZ0dR0plB9IvIrbPfx6ClxW60EfrNr PJ4Ql7m+sV9qBd9++lni/KfuVOFVHO4TtK2qLEYartX/yKEV5h6T9z87LpzYW/r3M63CRJ odljlPGmrDr1QOUOtDYOp5ShrAf8Mq2kbrXFADV31Qm1rX7/fhYKjG7BbhekTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794822407; 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=lm+KhAiLnB3Q1wy4bOYw9drVUBnS7YyxEg9RaSAeHmY=; b=Ps2UHIoP1pVU3jfMIlpo8UtkWmTQbxqZv4QUk4JNtYRIGxTyJsdpzSSkmXTw37DBeMchQX gAsx5omswKXS38bA4nqII12z5N7r7iMxc4+fjPrJEMT5fKCYDk8YBQ6hgvW/JpGeJfhbWj gC82AOr0bNr51oBGWumkxqxUwN+0IsY/3rKuPzSVEy1Yk5IiRE/bE4dJ+1KIAWTzE1yL4F KInKjJbDm6yGw8qUjf2lMomLEPwXhy85tNG6Mu5Uw116g3MPrpCXMApQIn53YU+uRjOIa6 YZZ0xCulnym4qRM9l6XtBx3oigDgbpmLiQngDNIkh2I5KkEaU/eiBcWtcppQ9w== 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 4jSjgW4MLrzplL for ; Mon, 16 Nov 2026 09:46:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 9627 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 16 Nov 2026 09:46:47 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Roman Bogorodskiy Subject: git: 5233aaccdce5 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 5233aaccdce59abfb80312cdbe94495516fd211f Auto-Submitted: auto-generated Date: Mon, 16 Nov 2026 09:46:47 +0000 Message-Id: <6afad107.9627.48710d3f@gitrepo.freebsd.org> The branch main has been updated by novel: URL: https://cgit.FreeBSD.org/src/commit/?id=5233aaccdce59abfb80312cdbe94495516fd211f commit 5233aaccdce59abfb80312cdbe94495516fd211f Author: Roman Bogorodskiy AuthorDate: 2026-11-15 09:19:44 +0000 Commit: Roman Bogorodskiy CommitDate: 2026-11-16 09:41:59 +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 --- 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 99dbefede237..23c5c24f0e99 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 */ @@ -143,8 +143,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! */