mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix vi mode crashes when going back one word (#246)
This bug was originally reported at <https://github.com/att/ast/issues/1467>. A crash can occur when using the 'b' or 'B' vi mode commands to go back one word. I was able to reproduce these crashes with 100% consistency on an OpenBSD virtual machine when ksh is compiled with -D_std_malloc. Reproducer: $ set -o vi $ asdf <ESC> <b or B> The fix is based on Matthew DeVore's analysis: > I suspect this is caused by this line: >> while (vi_isalph(tcur_virt) && tcur_virt >= first_virt) --tcur_virt; > which is in the b codepath. It checks vi_isalph(tcur_virt) before checking > if tcur_virt is in range. These two clauses should be reversed. Note that > line 316 is a similar check for pressing B, and there the tcur_virt value > is checked first. src/cmd/ksh93/edit/vi.c: - Check tcur_virt before using isalph() or isblank() to fix both crashes. At the start of the backword() while loop this check was performed twice, so the redundant check has been removed. src/cmd/ksh93/tests/pty.sh: - Add a regression test for the b, B, w and W editor commands.
This commit is contained in:
parent
f8de1f111d
commit
113a9392ff
4 changed files with 34 additions and 20 deletions
|
@ -770,5 +770,18 @@ w : XX\t
|
|||
r ^:test-1: : XXX\r\n$
|
||||
!
|
||||
|
||||
((SHOPT_VSH)) && tst $LINENO <<"!"
|
||||
L Using b, B, w and W commands in vi mode
|
||||
# https://github.com/att/ast/issues/1467
|
||||
|
||||
d 15
|
||||
p :test-1:
|
||||
w set -o vi
|
||||
r ^:test-1: set -o vi\r\n$
|
||||
w echo asdf\EbwBWa
|
||||
r ^:test-2: echo asdf\r\n$
|
||||
r ^asdf\r\n$
|
||||
!
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue