Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15747

[PATCH] Fix a problem `rl_bind_key' cannot create shadow binding for `C-@'

From Koichi Murase <myoga.murase@gmail.com>
Newsgroups gnu.bash.bug
Subject [PATCH] Fix a problem `rl_bind_key' cannot create shadow binding for `C-@'
Date 2019-12-19 00:43 +0800
Message-ID <mailman.1091.1576687436.1979.bug-bash@gnu.org> (permalink)
References <CAFLRLk9R5wexNV53fx6-V3rQEwKExfJsoDanZ9JqGFatG9GnKg@mail.gmail.com>

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

This is another report.

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -Wno-parentheses -Wno-format-security
uname output: Linux hp2019 5.2.13-200.fc30.x86_64 #1 SMP Fri Sep 6
14:30:40 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.0
Patch Level: 11
Release Status: maint

Description:

  One of the public interface of readline, the function
  `rl_bind_key (key, function)' does not work with key = 0 (C-@) when
  there are already bindings of keyseqs starting from "\C-@".
  This is because when `rl_bind_key' calls `rl_generic_bind',
  it fails to construct an appropriate untranslated keyseq for "\C-@".

Repeat-By:

  The function `rl_bind_key' is not widely used by current Bash codes,
  but to see the problem caused by this bug, one can use an older form
  of bind 'C-SPC:...' to register a shadow binding.

  $ LANG=C ./bash-3a7c642e --norc
  $ bind '"\C-@\C-@":"hello"'
  $ bind 'C-SPC:backward-char'
  $ echo* #<-- <C-@> (* is the cursor position)

  In the above example, the expected result is `ech*o' with `*' being
  the cursor position after the timeout, but the cursor does not move.
  But with the following newer form, we can get the expected result:

  $ LANG=C ./bash-3a7c642e --norc
  $ bind '"\C-@\C-@":"hello"'
  $ bind '"\C-@":backward-char'

Fix:

  I attach a patch `0001-....patch'. In the patch, the key '\0' is
  treated specially similarly to the key '\\'.

  By the way I think there is a memory leak in the same
  function. Could you check the second attached patch
  `0002-....patch'? I think if the original binding is a macro the
  memory block should be released before the pointer is overwritten.
  Actually I'm not quite sure, but at least in a similar function
  `rl_generic_bind', the macro string is released.

  I think there is a memory leak also in the `rl_generic_bind'.  The
  shadow macro which is stored in `map[ANYOTHERKEY].function' is not
  released before the overwrite. See the third patch `0003-....patch'.

Thank you,
Koichi

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

[PATCH] Fix a problem `rl_bind_key' cannot create shadow binding for `C-@' Koichi Murase <myoga.murase@gmail.com> - 2019-12-19 00:43 +0800

csiph-web