From 0f089a66e2f6f566923752c2bfcb8bc66ebc7135 Mon Sep 17 00:00:00 2001
From: Koichi Murase <myoga.murase@gmail.com>
Date: Tue, 20 Mar 2018 03:51:02 +0900
Subject: [PATCH 1/2] fix a bug that bind -x '"\C-@": unix-command' does not
 work

---
 bashline.c              |  2 +-
 lib/readline/bind.c     | 10 +++++++++-
 lib/readline/readline.h |  1 +
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/bashline.c b/bashline.c
index 5683d91..a162d90 100644
--- a/bashline.c
+++ b/bashline.c
@@ -4102,7 +4102,7 @@ bash_execute_unix_command (count, key)
   /* First, we need to find the right command to execute.  This is tricky,
      because we might have already indirected into another keymap, so we
      have to walk cmd_xmap using the entire key sequence. */
-  cmd = (char *)rl_function_of_keyseq (rl_executing_keyseq, cmd_xmap, &type);
+  cmd = (char *)rl_function_of_keyseq_with_length (rl_executing_keyseq, rl_key_sequence_length, cmd_xmap, &type);
     
   if (cmd == 0 || type != ISMACR)
     {
diff --git a/lib/readline/bind.c b/lib/readline/bind.c
index ef3331b..e77a2cd 100644
--- a/lib/readline/bind.c
+++ b/lib/readline/bind.c
@@ -763,12 +763,20 @@ rl_named_function (const char *string)
 rl_command_func_t *
 rl_function_of_keyseq (const char *keyseq, Keymap map, int *type)
 {
+  if (keyseq == 0)
+    return ((rl_command_func_t *) NULL);
+  return (rl_function_of_keyseq_with_length (keyseq, strlen (keyseq), map, type));
+}
+
+rl_command_func_t *
+rl_function_of_keyseq_with_length (const char *keyseq, int len, Keymap map, int *type)
+{
   register int i;
 
   if (map == 0)
     map = _rl_keymap;
 
-  for (i = 0; keyseq && keyseq[i]; i++)
+  for (i = 0; keyseq && i < len; i++)
     {
       unsigned char ic = keyseq[i];
 
diff --git a/lib/readline/readline.h b/lib/readline/readline.h
index c847e93..50fe6a6 100644
--- a/lib/readline/readline.h
+++ b/lib/readline/readline.h
@@ -332,6 +332,7 @@ extern char *rl_untranslate_keyseq PARAMS((int));
 
 extern rl_command_func_t *rl_named_function PARAMS((const char *));
 extern rl_command_func_t *rl_function_of_keyseq PARAMS((const char *, Keymap, int *));
+extern rl_command_func_t *rl_function_of_keyseq_with_length PARAMS((const char *, int, Keymap, int *));
 
 extern void rl_list_funmap_names PARAMS((void));
 extern char **rl_invoking_keyseqs_in_map PARAMS((rl_command_func_t *, Keymap));
-- 
2.9.5

