magicant / yash

Yet another shell
http://magicant.github.io/yash/
GNU General Public License v2.0
301 stars 28 forks source link

seg fault in alt+c completion #33

Closed vext01 closed 8 months ago

vext01 commented 8 months ago

Describe the bug

I can sometimes get a seg fault by repeatedly pressing alt+c to accept suggested completions.

To Reproduce

  1. start typing a command until yash offers a suggestion. I typed ls and yash offered ls /123.
  2. repeatedly type alt+c to accept arguments. I think i may have pressed enter after.
  3. seg fault sometimes.

Here's a low-quality backtrace:

Program received signal SIGSEGV, Segmentation fault.
memmove () at /usr/src/lib/libc/arch/amd64/string/memmove.S:88
88      movsq
Current language:  auto; currently asm
(gdb) bt
#0  memmove () at /usr/src/lib/libc/arch/amd64/string/memmove.S:88
#1  0x000001fc7a13b49a in wb_replace_force () from /usr/local/bin/yash
#2  0x000001fc7a15776e in cmd_self_insert () from /usr/local/bin/yash
#3  0x000001fc7a157438 in le_invoke_command () from /usr/local/bin/yash
#4  0x000001fc7a163640 in le_readline () from /usr/local/bin/yash
#5  0x000001fc7a122b25 in input_interactive () from /usr/local/bin/yash
#6  0x000001fc7a12a44a in next_token () from /usr/local/bin/yash
#7  0x000001fc7a12807a in parse_command_list () from /usr/local/bin/yash
#8  0x000001fc7a127dae in read_and_parse () from /usr/local/bin/yash
#9  0x000001fc7a146c38 in parse_and_exec () from /usr/local/bin/yash
#10 0x000001fc7a146aee in exec_input () from /usr/local/bin/yash
#11 0x000001fc7a1468dc in main () from /usr/local/bin/yash

I'll try to get a better one with symbols on master.

Environment (please complete the following information):

vext01 commented 8 months ago
gdb) bt
#0  memmove () at /usr/src/lib/libc/arch/amd64/string/memmove.S:88
#1  0x00000a47a472f4aa in wb_replace_force (
    buf=0xa47a47653b0 <le_main_buffer>, i=<optimized out>, bn=<optimized out>, 
    s=0x7a54ed32c2dc L"1\xa4765768ੇ", sn=<optimized out>) at strbuf.c:377
#2  0x00000a47a474b77e in wb_ninsert_force (
    buf=0xa47a47653b0 <le_main_buffer>, i=11314281103356, s=<optimized out>, 
    n=1) at ./../strbuf.h:381
#3  cmd_self_insert (c=49 L'1') at editing.c:831
#4  0x00000a47a474b448 in le_invoke_command (cmd=0xe48ba58cd21e2b34, 
    arg=1337245692 L'\x4fb4bffc') at editing.c:402
#5  0x00000a47a4757650 in read_next () at lineedit.c:329
#6  le_readline (prompt=..., trap=<optimized out>, resultp=0x7a54ed32c3f0)
    at lineedit.c:85
#7  0x00000a47a4716b25 in input_interactive (buf=0x7a54ed32c548, 
    inputinfo=0x7a54ed32c660) at input.c:263
#8  0x00000a47a471e44a in read_more_input (ps=0x7a54ed32c538) at parser.c:940
#9  next_token (ps=0x7a54ed32c538) at parser.c:1028
#10 0x00000a47a471c07a in parse_command_list (ps=0x7a54ed32c538, 
    toeol=<optimized out>) at parser.c:1836
#11 0x00000a47a471bdae in read_and_parse (info=<optimized out>, 
    resultp=0x7a54ed32c618) at parser.c:761
#12 0x00000a47a473ac48 in parse_and_exec (pinfo=0x7a54ed32c670, 
    finally_exit=<optimized out>) at yash.c:528
--Type <RET> for more, q to quit, c to continue without paging--
#13 0x00000a47a473aafe in exec_input (fd=<optimized out>, 
    name=<optimized out>, options=<optimized out>) at yash.c:501
#14 0x00000a47a473a8ec in main (argc=1, argv=<optimized out>) at yash.c:242
vext01 commented 8 months ago

That latter backtrace was generated by doing:

This was on a freshly cloned master branch with the patches from the openbsd ports and configured like:

CC=clang CPPFLAGS="-std=c99 -I/usr/local/include" LDFLAGS="-L/usr/local/lib" ./configure

I also notice that alt+c (which i believe should accept the next suggested word?) sometimes corrupts the capiltalisation of the suggestion.

Is there a way to change the alt+c binding to ctrl+arrowkey-right?

magicant commented 8 months ago

Thank you for reporting.

I also notice that alt+c (which i believe should accept the next suggested word?) sometimes corrupts the capiltalisation of the suggestion.

Is there a way to change the alt+c binding to ctrl+arrowkey-right?

Alt+c is by default bound to the emacs-capitalize-word command, which modifies the capitalization of the word at the cursor. If you just want to insert the suggested word, the forward-emacsword command would be what you want. It is by default bound to Alt+f, and also can be bound to Alt+c by running bindkey -e '\^[c' forward-emacsword.

magicant commented 8 months ago

Start the shell with yash --norcfile --emacs and the bug is reproducible just by hitting Alt+c without typing anything.

vext01 commented 8 months ago

Thanks for fixing this so fast!

One more question: \SR binds shift+→. Is there a way to bind ctrl+→?

It's not \^\R :)

magicant commented 8 months ago

https://osdn.net/projects/yash/ticket/46524#comment:3863:46524:1674056716

Many terminals reserve the Ctrl-Arrow key for their own functions such as scrolling and window switching, and I don't think common terminfo databases define capabilities for the Ctrl-Arrow key. That means the current architecture of yash cannot support binding the Ctrl-Arrow key in the same way as other keys. But if you are sure that your terminal emits ^[[1;5D and ^[[1;5C for the Ctrl-Left/Right key, the following commands may help.

bindkey -e '\^[[1;5D' backward-emacsword
bindkey -e '\^[[1;5C' forward-emacsword