-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pressing 'b' to go to beginning of command in vi mode results in crash #1467
Comments
I would advice, for the time being, to go back to using /bin/ksh on OSX which is the last stable release of ksh93 (i.e. ksh93u+). vi mode works just fine with it and the segfault you report here for ksh2020 is not seen with it. ksh2020 ( which is what homebrew is providing via this repo to you) has known problems and the project is currently in a state of readjustment, see #1466 |
@jghub Thank you for the tip. I am new to ksh and I assumed the latest version would be the best. Reading some of the issues here, it sounds like that is not necessarily the case. |
hopefully you stay with it. benchmarking some busy loops against bash or zsh might be helpful to understand that ksh93 is in a different league for scripting/programming (and the only of the Bourne shell descendants supporting floating point arithmetic). if you want to dive deeper into ksh this book still is highly recommendable.
I agree, obviously. for now, I presume OSX if you encounter strange behaviour or bugs, please report them (for now, here, in the future hopefully in a new "ksh93 legacy" repo.). |
I'm using the FreeBSD ksh93-devel port, updated a day prior to the rollback (8cf92b2). I have no problems with "b". You might want to try the latest ksh2020 branch. |
I tried building at that commit and am still getting the same problem. I assume there are a lot of other factors about whether an illegal access will be detected, like the compiler used and the OS, which would explain why we're seeing different behavior. Switching the two clauses in the while loop condition did fix it, as I suspected.
I have been trying out ksh for this exact reason - it sounds like a better programming language than other shells while still feeling a lot like a normal POSIX shell for interactive use.
Thank you, I'll keep a note of this. |
Same with me, no problems, in ksh2020 version : 2020.0.0-beta1-208-g2f06a34e-dirty |
This is a heisenbug. This bug is present in ksh93u+. I had determined the root cause of this issue a few hours after this issue was opened. But I waited till now to see if anyone would take the issue seriously. I was not surprised in seeing the new people in control of the project assuming the bug was introduced by me. That is, since the ksh93v- or ksh93u+ release. The bug is in the following Lines 688 to 689 in 27e7217
This bug will rarely be observed because it requires that a) the buffer pointed to by b) the preceding page of virtual memory cannot be read. The easiest way to reproduce this problem on the 2020.0.0 branch is to build
That sort of reproduction is immensely harder now that the code is once again using the AST vmalloc subsystem rather than the platform malloc subsystem. This means that using tools like ASAN are, once again, impossible. Not to mention that the project no longer includes any ability to run interactive tests. Something @siteshwar and I addressed in the work leading up to the 2020.0.0 release by introducing The first big change I made was replacing the AST vmalloc subystem with the OS malloc subsystem. That |
You did not replace the system MALLOC w/ AST VMALLOC in ksh2020, did you? I hope not. |
@DavidMorano, I think @krader1961 is referring to #1466, the rewinding of this repo to ksh93u. I don't see why ksh2020 can't live on elsewhere. It is available on the ksh2020 branch. This is just a repo. Forks happen. |
in the so-called "stable" ksh2020 release it is 100% reproducible in OSX (like for the OP). nothing of a heisenbug to it at all (on that platform, anyway). OTOH, I was not able to make ks93u+ segfault ONCE under OSX due to vi-editor misbehaviour in >5 years using this editor mode. if krader were technically right to claim that it is a bug in ksh93u+, he should provide an example how to trigger that bug in ksh93u+ I'd say. if that is not possible it is not a real bug but a perceived or theoretical one (which might or might not be worth to fix at some point).
for the record and in order to prevent krader's misinformation to take hold: there are no "new people in control of the project". @gordonwoodhull and the ATT/AST team came to a (good) decision due to the situation explained in #1464 and #1466 and revoked commit rights to krader (and everybody else external to ATT) and rewound to ksh93u+ while moving ksh2020 to the side on a branch. "not taking the issue seriously": a) this issue concerns ksh2020 and is not observed with ksh93u+. b) future work on ksh93u+ and ksh2020 will have to happen in (separate) forks of the present repo. nobody assumed anything. the factual statement is "it is a 100% reproducible bug in the ksh2020 release under OSX and the segfault is not observed in ksh93u+ at all with the same OS". there is no official ksh93v- release. ksh93v- was/is beta. ksh2020 is a descendant of this beta-software and did never manage to make the new, still buggy ksh93v- features work or get otherwise out of beta-state. rather those features were deleted. AFAIK, ksh2020 does provide no desirable functionality beyond what ksh93u+ provides but is way more buggy due to its ksh93v- heritage plus its own new problems than ksh93u+. and slower. "buggy" as in "does not work properly, misbehaves, segfaults".
this bug is always observed with the ksh2020 release under OSX. regarding the future of ksh2020: as @gordonwoodhull already pointed out, krader is free to fork and go ahead with it. other people will go ahead starting from ksh93u+ it seems. |
This bug was originally reported at <att#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 machince 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. src/cmd/ksh93/tests/pty.sh: - Add a regression test for the b, B, w and W editor commands.
This bug was originally reported at <att#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 machince 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 bug was originally reported at <att#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.
Description of problem:
Pressing
b
to go to beginning of command in vi mode results in crashKsh version:
(installed via Homebrew on macOS a few days ago)
How reproducible:
100% of the time.
Steps to reproduce:
Actual results:
Crash with stack trace:
Expected results:
go to beginning of line.
Additional info:
Does not repro if I press
B
rather thanb
I suspect this is caused by this line:
ast/src/cmd/ksh93/edit/vi.c
Line 319 in c99e9ff
which is in the
b
codepath. It checksvi_isalph(tcur_virt)
before checking iftcur_virt
is in range. These two clauses should be reversed. Note that line 316 is a similar check for pressingB
, and there thetcur_virt
value is checked first.I don't have an environment to build and run the automated tests. If I have a chance to set one up, I'll try to send a patch.
The text was updated successfully, but these errors were encountered: