Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com X-Authentication-Warning: slinky.cs.nyu.edu: pechtcha owned process doing -bs Date: Wed, 2 Oct 2002 22:46:23 -0400 (EDT) From: Igor Pechtchanski Reply-To: cygwin AT cygwin DOT com To: cygwin AT cygwin DOT com cc: Jelks Cabaniss Subject: [PATCH] Re: readline Bug! ;-) [was: Bash Bug! (was: Bug in rxvt 2.7.2 ...)] In-Reply-To: Message-ID: Importance: Normal MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="-559023410-1804928587-1033613183=:13573" ---559023410-1804928587-1033613183=:13573 Content-Type: TEXT/PLAIN; charset=US-ASCII Well, I guess I've figured this one out... The bug was in readline-4.3. I'm attaching patches for both bash-2.05b-5 and readline-4.3-1 (nearly identical). There is a *long* description of the bug and the fix below for those who are interested, feel free to skip. Igor On Wed, 2 Oct 2002, Igor Pechtchanski wrote: > Hey, as long as we're shifting the blame, let's shift it correctly ;-) > Details below... > > On Tue, 1 Oct 2002, Jelks Cabaniss wrote: > > > Igor Pechtchanski wrote: > > > > > > > As for the Ctrl-Left, this is something odd in bash. I > > > > > can get the same behavior in a command window running bash, > > > > > or even by typing Esc O c. Bash running on Linux does not > > > > > seem to have this problem. > > > > I wrote, speaking about CTRL+Left: > > > > > > Here it crashes rxvt, but not the bash console. WinXP. > > > > > I can confirm Esc O c crashing a bash command window on Win2k SP2. > > > Seems like Esc O kills bash... > > > > Ah, you're right! CTRL+Left doesn't crash bash here, but Esc O c sends > > it flying out the window in flames. > > > > /Jelks > > This actually seems to be a readline bug. Bash dies with a SIGSEGV > because of an infinite recursion in _rl_dispatch_subseq() in the readline > library. I've included a transcript of a gdb session below. The keys > pressed were ' O '. I'm going to try to debug it tomorrow, > but if anyone more familiar with the readline library wants to take a shot > at it earlier, it's fine with me. :-) > > [snip] > > $ gdb -nw ./bash.exe > GNU gdb 5.0 (20010428-3) > [snip] > (gdb) run -i > Starting program: ./bash.exe -i > [snip] > Program received signal SIGSEGV, Segmentation fault. > 0x0045bfc7 in _rl_dispatch_subseq (key=256, map=0x10028188, got_subseq=0) > at readline.c:529 > 529 return _rl_dispatch_subseq (key, map, 0); > (gdb) where > #0 0x0045bfc7 in _rl_dispatch_subseq (key=256, map=0x10028188, got_subseq=0) > at readline.c:529 > #1 0x0045bfbc in _rl_dispatch (key=256, map=0x10028188) at readline.c:529 > #2 0x0045c0a4 in _rl_dispatch_subseq (key=256, map=0x10028188, got_subseq=0) > at readline.c:570 > #3 0x0045bfbc in _rl_dispatch (key=256, map=0x10028188) at readline.c:529 > #4 0x0045c0a4 in _rl_dispatch_subseq (key=256, map=0x10028188, got_subseq=0) > at readline.c:570 > #5 0x0045bfbc in _rl_dispatch (key=256, map=0x10028188) at readline.c:529 > [ Zillions of identical frames here ] > ---Type to continue, or q to quit---q > Quit > [snip] > (gdb) q > The program is running. Exit anyway? (y or n) y > $ Description of the bug and the fix (long and overly technical, feel free to skip): Readline has a mechanism for allowing two mappings where one is a prefix of another, e.g., from .inputrc: "ABCD": dump-variables "A": dump-functions The idea is that if it encounters a prefix of the longer pattern, readline will keep reading characters until it either matches the pattern (in which case it simply executes the mapping) or sees it diverge (in which case it backtracks and executes the mapping for the shorter pattern, and then reinterprets all pending characters). Readline accomplishes that by keeping a "default" map entry in which it stores the target of the shorter mapping. If it encounters a character for which there is no continuation in the sequence, it will use this "default" entry to try to match a shorter sequence or to backtrack. Readline also has a special mapping called rl_do_lowercase_version, which simply redirects the mapping to that of the lowercase letter. This is useful for keeping Meta-a and Meta-A in sync, but doesn't work too well if it's the saved "default" mapping. What readline tried to do is convert the "default" key value to lowercase (which, of course, returned the same value) and try to dispatch on that, which resulted in an infinite loop. The fix is to check whether the default action is rl_do_lowercase_version, and if it is, dispatch explicitly on the lowercase of the current key. This is a bit kludgy, in that it actually does an extra evaluation of the mapping, probably breaking the encapsulation, and certainly duplicating code... If anyone can think of a more elegant solution, I'd be happy. If not, this'll work. Oh, and IMO the default empty mapping created by rl_make_bare_keymap() incorrectly set all entries for capital letters to rl_do_lowercase_version (which is wrong for most mappings), so I fixed that in this patch as well. Well, that's it, sorry for the rant. Igor -- http://cs.nyu.edu/~pechtcha/ |\ _,,,---,,_ pechtcha AT cs DOT nyu DOT edu ZZZzz /,`.-'`' -. ;-;;,_ igor AT watson DOT ibm DOT com |,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow! "Water molecules expand as they grow warmer" (C) Popular Science, Oct'02, p.51 ---559023410-1804928587-1033613183=:13573 Content-Type: TEXT/PLAIN; charset=US-ASCII; name="bash-2.05b-5.patch" Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename="bash-2.05b-5.patch" LS0tIC4vbGliL3JlYWRsaW5lL2tleW1hcHMuYy1vcmlnCTIwMDItMTAtMDIg MjA6MTI6MDQuMDAwMDAwMDAwIC0wNDAwDQorKysgLi9saWIvcmVhZGxpbmUv a2V5bWFwcy5jCTIwMDItMTAtMDIgMjA6NDk6MzcuMDAwMDAwMDAwIC0wNDAw DQpAQCAtNjQsMTEgKzY0LDEzIEBAIHJsX21ha2VfYmFyZV9rZXltYXAgKCkN CiAgICAgICBrZXltYXBbaV0uZnVuY3Rpb24gPSAocmxfY29tbWFuZF9mdW5j X3QgKilOVUxMOw0KICAgICB9DQogDQorI2lmIDANCiAgIGZvciAoaSA9ICdB JzsgaSA8ICgnWicgKyAxKTsgaSsrKQ0KICAgICB7DQogICAgICAga2V5bWFw W2ldLnR5cGUgPSBJU0ZVTkM7DQogICAgICAga2V5bWFwW2ldLmZ1bmN0aW9u ID0gcmxfZG9fbG93ZXJjYXNlX3ZlcnNpb247DQogICAgIH0NCisjZW5kaWYN CiANCiAgIHJldHVybiAoa2V5bWFw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FtBTllPVEhF UktFWV0uZnVuY3Rpb24pDQogCSAgICB7DQogCSAgICAgIC8qIFdlIGRpZG4n dCBtYXRjaCAociBpcyBwcm9iYWJseSAtMSksIHNvIHJldHVybiBzb21ldGhp bmcgdG8NCg== ---559023410-1804928587-1033613183=:13573 Content-Type: TEXT/PLAIN; charset=US-ASCII; name="readline-4.3-1.patch" Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename="readline-4.3-1.patch" LS0tIC4va2V5bWFwcy5jLW9yaWcJMjAwMi0xMC0wMiAyMTozNzo1NS4wMDAw MDAwMDAgLTA0MDANCisrKyAuL2tleW1hcHMuYwkyMDAyLTEwLTAyIDIyOjA5 OjI3LjAwMDAwMDAwMCAtMDQwMA0KQEAgLTY0LDExICs2NCwxMyBAQCBybF9t YWtlX2JhcmVfa2V5bWFwICgpDQogICAgICAga2V5bWFwW2ldLmZ1bmN0aW9u ID0gKHJsX2NvbW1hbmRfZnVuY190ICopTlVMTDsNCiAgICAgfQ0KIA0KKyNp ZiAwDQogICBmb3IgKGkgPSAnQSc7IGkgPCAoJ1onICsgMSk7IGkrKykNCiAg ICAgew0KICAgICAgIGtleW1hcFtpXS50eXBlID0gSVNGVU5DOw0KICAgICAg IGtleW1hcFtpXS5mdW5jdGlvbiA9IHJsX2RvX2xvd2VyY2FzZV92ZXJzaW9u Ow0KICAgICB9DQorI2VuZGlmDQogDQogICByZXR1cm4gKGtleW1hcCk7DQog fQ0KLS0tIC4vcmVhZGxpbmUuYy1vcmlnCTIwMDItMTAtMDIgMjE6Mzc6MzYu MDAwMDAwMDAwIC0wNDAwDQorKysgLi9yZWFkbGluZS5jCTIwMDItMTAtMDIg MjI6MDk6MzcuMDAwMDAwMDAwIC0wNDAwDQpAQCAtNjQ1LDEyICs2NDUsMjQg QEAgX3JsX2Rpc3BhdGNoX3N1YnNlcSAoa2V5LCBtYXAsIGdvdF9zdWJzZQ0K IAkgIHIgPSBfcmxfZGlzcGF0Y2hfc3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zaGluZyBhbnkgbmVjZXNzYXJ5IGlucHV0IGJh Y2sgb250bw0KKyAgICAgICAgICAgICAgICAgdGhlIGlucHV0IHF1ZXVlIHdp dGggX3JsX3VuZ2V0X2NoYXIuICovDQorI2lmIDANCisgICAgICAgICAgICAg IHIgPSBfcmxfZGlzcGF0Y2ggKEFOWU9USEVSS0VZLCBGVU5DVElPTl9UT19L RVlNQVAgKG1hcCwga2V5KSk7DQorI2Vsc2UNCisgICAgICAgICAgICAgIEtl eW1hcCBtID0gRlVOQ1RJT05fVE9fS0VZTUFQIChtYXAsIGtleSk7DQorICAg ICAgICAgICAgICBpbnQgdHlwZSA9IG1bQU5ZT1RIRVJLRVldLnR5cGU7DQor ICAgICAgICAgICAgICBmdW5jID0gbVtBTllPVEhFUktFWV0uZnVuY3Rpb247 DQorICAgICAgICAgICAgICBpZiAodHlwZSA9PSBJU0ZVTkMgJiYgZnVuYyA9 PSBybF9kb19sb3dlcmNhc2VfdmVyc2lvbikNCisgICAgICAgICAgICAgICAg ciA9IF9ybF9kaXNwYXRjaCAoX3JsX3RvX2xvd2VyIChrZXkpLCBtYXApOw0K KyAgICAgICAgICAgICAgZWxzZQ0KKyAgICAgICAgICAgICAgICByID0gX3Js X2Rpc3BhdGNoIChBTllPVEhFUktFWSwgbSk7DQorI2VuZGlmDQorICAgICAg ICAgICAgfQ0KIAkgIGVsc2UgaWYgKHIgJiYgbWFwW0FOWU9USEVSS0VZXS5m dW5jdGlvbikNCiAJICAgIHsNCiAJICAgICAgLyogV2UgZGlkbid0IG1hdGNo IChyIGlzIHByb2JhYmx5IC0xKSwgc28gcmV0dXJuIHNvbWV0aGluZyB0bw0K ---559023410-1804928587-1033613183=:13573 Content-Type: text/plain; charset=us-ascii -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ ---559023410-1804928587-1033613183=:13573--