hanslub42 / rlwrap

A readline wrapper
GNU General Public License v2.0
2.57k stars 150 forks source link

rlwrap crashes when .inputrc binds "\M-\C\-<key>" #95

Closed nephewtom closed 3 years ago

nephewtom commented 5 years ago

rlwrap fails to run on Windows Subsystem for Linux (WSL) on Windows 10.

etomort@ES-00002604:~/playground/python
$ cat read.py
while True:
    inp = raw_input("> ")
    print "You entered", inp

etomort@ES-00002604:~/playground/python
$ rlwrap python read.py
rlwrap: warning: Owner of /mnt/c/Users/etomort/elx/.python_history and your effective UID don't match. History will be read-only

warnings can be silenced by the --no-warnings (-n) option
>
rlwrap: Oops, crashed (caught SIGSEGV) - this should not have happened!
If you need a core dump, re-configure with --enable-debug and rebuild
Resetting terminal and cleaning up...

Version information:

etomort@ES-00002604:~/playground/python
$ rlwrap --version
rlwrap 0.43

etomort@ES-00002604:~/playground/python
$ rlwrap --version
rlwrap 0.43
etomort@ES-00002604:~/playground/python
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.1 LTS
Release:        18.04
Codename:       bionic

etomort@ES-00002604:~/playground/python
$ systeminfo.exe | grep OS
OS Name:                   Microsoft Windows 10 Pro
OS Version:                10.0.16299 N/A Build 16299
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Member Workstation
OS Build Type:             Multiprocessor Free
BIOS Version:              HP Q78 Ver. 01.04.00, 12-Sep-18

I tried rlwrap binary from Ubuntu and clone/compile/run this Github rlwrap. Both fail in the same manner.

Best Regards.

nephewtom commented 5 years ago

It seems something on my user space, not WSL, is breaking rlwrap.
https://github.com/Microsoft/WSL/issues/3824#issuecomment-460414884

I still have to found what it is...

nephewtom commented 5 years ago

Ok, I just found it and it seems having this .inputrc file crashes readline:

# Based on Brendan Miller's initial bash .inputrc
# INSTALL
# to install, rename this file to just ".inputrc"
# place this file in your home dir. e.g. ~/.inputrc
# restart your terminal. Then, bash's keybinding for editing
# should be like ErgoEmacs.
# If no key works, try replace all \e to \M-. That's means change Esc to Meta key.

set editing-mode emacs
"\C-b": backward-char
"\C-f": forward-char
"\M-b": backward-word
"\C-M-b": backward-word
"\M-f": forward-word
"\C-M-f": forward-word
"\C-k": kill-line
"\M-DEL": backward-kill-word
"\M-d": kill-word
"\C-d": delete-char
"\C-x u": undo
"\C-x <timeout>": kill-region
"\C-c <timeout>": copy-region-as-kill
"\C-v": yank
"\C-s": forward-search-history
"\C-r": reverse-search-history

I stumbled with a similar issue with clink.

hanslub42 commented 5 years ago

Could you find out (for the benefit of those with similar problems) which line(s) in your .inputrc are to blame? The lines with <timeout> look odd to me, but they shouldn't crash readline, of course.

nephewtom commented 5 years ago

These two lines cause rlwrap to crash.

"\C-M-f": forward-word
"\C-M-b": backward-word

Just having a .inputrc file with any of those ones, crashes rlwrap:

rlwrap

Hope that helps.

hanslub42 commented 5 years ago

I can reproduce the segfault on my linux system - this isn't a WSL-specific problem at all .

gdb rlwrap core gives:

Program terminated with signal SIGSEGV, Segmentation fault.  
#0  0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x00007fddff334106 in rl_callback_read_char () from /lib64/libreadline.so.7
#2  0x0000000000405b51 in main_loop () at main.c:543
#3  0x0000000000403ad2 in main (argc=2, argv=0x7ffd656c8b08) at main.c:178

At first sight this looks like readline bug that only shows itself with programs that use the readline callback interface (there aren't many of those, but rlwrap is one of them)

nephewtom commented 5 years ago

Yep, I just reproduced it in Linux Mint 19 on VirtualBox.

I also experienced several problems with clink which also uses readline.
I reported one which did not make it crash but had an annoying behavior. And commented on another one which seems it makes it crash.

By the way, are you a violinist? Just curiosity...

hanslub42 commented 5 years ago

Yes, there are many musicians that are mathematicians/programmers as well (and the other way round), and I'm one of them....

Building libreadline with CFLAGS=-g, linking rlwrap with the result and then using gdb shows that the crash happens when (*rl_linefunc) (line); is executed by readline in callback.c:281 (readline 8.0) with a NULL rl_linefunc. This means that this is almost certainly a rlwrap-specific bug, as rlwrap performs some trickery temporarily removing the line_handler when a line is accepted.

This will take some time to sort out, in the meantime I changed the subject of this issue to better reflect the scope of the problem.

nephewtom commented 5 years ago

Yes, there are many musicians that are mathematicians/programmers as well (and the other way round), and I'm one of them....

Nice! I have played guitar (classical & flamenco) and some piano, though I do not play much lately. But I know I will practice again soon.

Building libreadline with CFLAGS=-g, linking rlwrap with the result and then using gdb shows that the crash happens when (*rl_linefunc) (line); is executed by readline in callback.c:281 (readline 8.0) with a NULL rl_linefunc. This means that this is almost certainly a rlwrap-specific bug, as rlwrap performs some trickery temporarily removing the line_handler when a line is accepted.

This will take some time to sort out, in the meantime I changed the subject of this issue to better reflect the scope of the problem.

Fine, I am glad to report this if it helps to improve rlwrap. I mostly use it with sqlplus since 2012, which I can not stand it without it. Thanks for you dedication!

hanslub42 commented 3 years ago

I'm not convinced that \M-\C-<key> is the right syntax to use. When I add "\M-\C-b": backward-word to my .inputc even the simplest possible test program that usesreadline in callback mode behaves weirdly (I have to press ENTER twice to get it to accept a line) - although it doesn't crash.

On the other hand, if I use the syntax

"\e\C-b": backward-word

all is well, there are no crashes, and ALT+CTRL+b behaves as expected.