From nobody Wed Jun 5 18:22:43 2024 X-Original-To: bugs@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 4VvbRR6NQQz5LVhj for ; Wed, 05 Jun 2024 18:22:43 +0000 (UTC) (envelope-from bugzilla-noreply@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VvbRR5HXGz4XgH for ; Wed, 5 Jun 2024 18:22:43 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1717611763; a=rsa-sha256; cv=none; b=JvnqsuY0muHkvMvbYty+uUCkkKjrVT1W0tQaU7exitOjxgBY0GBXAR4tW1DqkRf3WdHcbe 9ALWHwuGPsfeo0EMR/9SSOefwyjjpfqD5nIk70v+j+ufMnLLKai7nezKbIcCBPIHEfRJKG 9XPk1GGchCELwSacklM86bkfKHmVwIWLEUioFzrCZMATRfxbVMViQN6TU2n1ky8xu/s/Ay QDmBWnANKY/WAjszAPHXRkMWQrrL97DA5167ooDwRqMVa4AMkv7m8PY+R0G2CVpd/7I8R9 Qbj80y4Qjfqa+O4aSwTnKi275ww1I/q4mxNqZyaxHTjmjImCnNCS73bOtV0rxg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717611763; 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=mPzuFP3I/KnRqRbXlzYrfVeVh7+FDnTrGkvl+8//4Dk=; b=beNsI3VDErxXdQlYZYRAmv/CTP2anDG6ew+OroFmV/Q0qkyxkJy1azqyja3H5csIIFHSKu NhuWJlVSHazZLXGLCFstjtO3BT7rDbshj7BXWU4WYFt30usNKuIcwhABDyAfbrBfbTm4yq /naGGUxSgbC/MNelf2dwYz2zd3AJKQvuqRFlGDmpDWRuXHnxwEQXP6OfnjZ4mbg9oZ/e8K ktcb1ogf/isOKNJm1nQli64hnxi7rlG1Sfw/PuQs5G27tU0XKC3qOG1VJEspn8R3hpIWGU JL92+Rsx9fllShUKhuZJKdGAxBwCAobrHKapKS6D2PmyCspdgYNHOQ3wnASsfA== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (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 4VvbRR4t4Jz1CLr for ; Wed, 5 Jun 2024 18:22:43 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 455IMhLX051864 for ; Wed, 5 Jun 2024 18:22:43 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 455IMhOu051862 for bugs@FreeBSD.org; Wed, 5 Jun 2024 18:22:43 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 279545] libedit vi_change_case() can read before the start of a buffer Date: Wed, 05 Jun 2024 18:22:43 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: rtm@lcs.mit.edu X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@FreeBSD.org MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D279545 Bug ID: 279545 Summary: libedit vi_change_case() can read before the start of a buffer Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: bin Assignee: bugs@FreeBSD.org Reporter: rtm@lcs.mit.edu If the buffer has just one character in it, then vi_change_case() will set cursor to the start of the buffer and then call re_fastaddc(): vi_change_case(EditLine *el, wint_t c) { ...; if (++el->el_line.cursor >=3D el->el_line.lastchar) { el->el_line.cursor--; re_fastaddc(el); And then re_fastaddc()'s "-1" is an invalid reference: re_fastaddc(EditLine *el) { ...; c =3D el->el_line.cursor[-1]; One can reproduce this using valgrind on /bin/sh: $ set -o vi $ x ESC ~ (that is, type x, then escape, then ~) Invalid read of size 4 at 0x4891EF2: re_fastaddc (rtm/freebsd/contrib/libedit/refresh.c:1158) by 0x489C95F: vi_change_case (rtm/freebsd/contrib/libedit/vi.c:272) by 0x4889747: el_wgets (rtm/freebsd/contrib/libedit/read.c:540) by 0x4879B3C: el_gets (rtm/freebsd/contrib/libedit/eln.c:75) by 0x123D6E: preadfd (rtm/freebsd/bin/sh/input.c:138) by 0x12387A: preadbuffer (rtm/freebsd/bin/sh/input.c:210) by 0x1326C5: xxreadtoken (rtm/freebsd/bin/sh/parser.c:910) by 0x12E4FC: readtoken (rtm/freebsd/bin/sh/parser.c:827) by 0x12E379: parsecmd (rtm/freebsd/bin/sh/parser.c:222) by 0x129786: cmdloop (rtm/freebsd/bin/sh/main.c:206) by 0x1295D2: main (rtm/freebsd/bin/sh/main.c:167) Address 0x552188c is 4 bytes before a block of size 4,096 alloc'd at 0x4851735: calloc (vg_replace_malloc.c:1599) by 0x48740AA: ch_init (rtm/freebsd/contrib/libedit/chared.c:399) by 0x4877714: el_init_internal (rtm/freebsd/contrib/libedit/el.c:107) by 0x48775B0: el_init_fd (rtm/freebsd/contrib/libedit/el.c:124) by 0x487754A: el_init (rtm/freebsd/contrib/libedit/el.c:66) by 0x1215BC: histedit (rtm/freebsd/bin/sh/histedit.c:183) by 0x12C1ED: optschanged (rtm/freebsd/bin/sh/options.c:130) by 0x12BEA1: procargs (rtm/freebsd/bin/sh/options.c:121) by 0x1293EC: main (rtm/freebsd/bin/sh/main.c:131) FreeBSD stock14 15.0-CURRENT FreeBSD 15.0-CURRENT #22 main-n270479-ecd1d1f1dac4-dirty: Thu May 30 18:42:11 AST 2024=20=20=20=20 root@stock14:/usr/obj/usr/src/amd64.amd64/sys/GENERIC amd64 --=20 You are receiving this mail because: You are the assignee for the bug.=