From nobody Thu Nov 19 17:07:46 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 4jVlJy6SjQz71Svt for ; Thu, 19 Nov 2026 17:07:46 +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 4jVlJy42lpz4LRZ for ; Thu, 19 Nov 2026 17:07:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795108066; 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=WGkBFdjZh5S26q3MKnlClUtLzkyPtPAgTGBbHbCoNIg=; b=Q3EYK/M3BnH8sMI9E99mqrGi/yDYsCxzl+RPeprYgYS2afY0YITjjrXeNbTpJZ8UcsVtHR 9qGJlGwX754xe4s/MS6E7TVKHvzCKIh481laKbn/Wmne8Jho6EECPQ5kwtIn+TSOJbHzL2 aCwh0G3Opbgq9Ty6v9f2ZWTXO5ktAhsixxgte4JvaFZmVaMyLtImAakZfveRcOe5P7kUIj KgPTitPh87CjQXYUqCbmT+H6L6M0KKAbWnSWobAgFzhEylfLgh2QElXQCmfI7bHnAVjUeS mas4wnF1NQZ24GfE5II6Q2BMsvgHnVMVB0Sb2ecKGRSfG2iiRf8//Hz+TLTymg== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1795108066; b=jeQRYRZpqj3L9g237K+KI+RjTPDssIU5pEPKdk3qAncz4uuqjsu4FDfOGKlQPlBioGjI16 pHXkOwllxUefdEKnR+p5xEoicfrLwhxc6PWaPwX1KRoqveDdToG19VN4fzc+u7fclISEMn quaCe+uG3b3IR4P1Ak3eWB8lAXpmMeSNVGGu0PP1w0OJDjdSJfuVGFX+R3FS6yEqCgCdMB KkI7NUwm/3DWhJRDEHDZLYyKQ9YL3kUw1fwyfztm3VPaXwBShyKw6otcG0CB8Zx5uYBhrT lQ5CCqDwDRcKfZBljimgMsbpsJ72j5ujIisYItECY2cGSAuowUswH6qkGXLI1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795108066; 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=WGkBFdjZh5S26q3MKnlClUtLzkyPtPAgTGBbHbCoNIg=; b=Kp8XszND9NTNfCi0I2ZVTn8jItYjByHJT507L4zFh9HXGwSSTpVfpeTtAcv6NH1n0sjhgf SoKPBnmc7fAiylGgbKGwca4DZk95jty1p9c1FCjuoi9oEh8nyL+brZrUdGIyFJDbZkVEiB xFtm7YOuPZt8RQhBS3WyDkHwZ8GHFplyWPInyCMr3K4zA6Fku8ntrqzcmVnbU0AJNxIts5 YtIHDKu0qeapsQH0df7vqWSREEtsxZnX8bRRfZ/tcvyfx4w7YPf2Dn3VWMvAqBo2jy3qQ0 0OzVZBmblAdz4GMGk3UxYXD1TPu/0GlDO7durR0FP7RSB4pmAbmVgOEXprV4Uw== 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 4jVlJy3QKqz18Mm for ; Thu, 19 Nov 2026 17:07:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 15ea6 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 19 Nov 2026 17:07:46 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Roman Bogorodskiy Subject: git: cd2ec1b45f35 - stable/15 - 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/15 X-Git-Reftype: branch X-Git-Commit: cd2ec1b45f3596bc72da0283592138ba7ecd1286 Auto-Submitted: auto-generated Date: Thu, 19 Nov 2026 17:07:46 +0000 Message-Id: <6aff2ce2.15ea6.7c8489c6@gitrepo.freebsd.org> The branch stable/15 has been updated by novel: URL: https://cgit.FreeBSD.org/src/commit/?id=cd2ec1b45f3596bc72da0283592138ba7ecd1286 commit cd2ec1b45f3596bc72da0283592138ba7ecd1286 Author: Roman Bogorodskiy AuthorDate: 2026-11-15 09:19:44 +0000 Commit: Roman Bogorodskiy CommitDate: 2026-11-19 17:04:07 +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 b6cde0e63aa7..77f14132bc16 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! */