about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>2021-09-08 09:51:43 +0900
committerJun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>2021-09-08 09:51:43 +0900
commit2a7945a900c8a1b1866ad31ee5e95db5b0ddb50a (patch)
tree104fbaa1271df14eb77c7f6c9c07076cbde33ed7
parentbb61da36aaeeaa70413cdf5bc66d7a71194f93e5 (diff)
downloadzsh-2a7945a900c8a1b1866ad31ee5e95db5b0ddb50a.tar.gz
zsh-2a7945a900c8a1b1866ad31ee5e95db5b0ddb50a.tar.xz
zsh-2a7945a900c8a1b1866ad31ee5e95db5b0ddb50a.zip
49377: fix segfault by 'bindkey -d' with reordered keymapnamtab
-rw-r--r--ChangeLog5
-rw-r--r--Src/Zle/zle_keymap.c22
-rw-r--r--Test/X03zlebindkey.ztst15
3 files changed, 41 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index eb75cf235..da91b0c6c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2021-09-08  Jun-ichi Takimoto  <takimoto-j@kba.biglobe.ne.jp>
+
+	* 49377: Src/Zle/zle_keymap.c, Test/X03zlebindkey.ztst: fix
+	segfalut by 'bindkey -d' with reordered keymapnamtab
+
 2021-09-06  Bart Schaefer  <schaefer@zsh.org>
 
 	* Stephane Chazelas: 45180: Doc/Zsh/contrib.yo,
diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c
index 2389ab754..d90838f03 100644
--- a/Src/Zle/zle_keymap.c
+++ b/Src/Zle/zle_keymap.c
@@ -155,7 +155,7 @@ createkeymapnamtab(void)
     keymapnamtab = newhashtable(7, "keymapnamtab", NULL);
 
     keymapnamtab->hash        = hasher;
-    keymapnamtab->emptytable  = emptyhashtable;
+    keymapnamtab->emptytable  = emptykeymapnamtab;
     keymapnamtab->filltable   = NULL;
     keymapnamtab->cmpnodes    = strcmp;
     keymapnamtab->addnode     = addhashnode;
@@ -178,6 +178,26 @@ makekeymapnamnode(Keymap keymap)
     return kmn;
 }
 
+/**/
+static void
+emptykeymapnamtab(HashTable ht)
+{
+    struct hashnode *hn, *hp;
+    int i;
+
+    for (i = 0; i < ht->hsize; i++) {
+	for (hn = ht->nodes[i]; hn;) {
+	    KeymapName kmn = (KeymapName) hn;
+	    hp = hn->next;
+	    zsfree(kmn->nam);
+	    unrefkeymap(kmn->keymap);
+	    zfree(kmn, sizeof(*kmn));
+	    hn = hp;
+	}
+	ht->nodes[i] = NULL;
+    }
+    ht->ct = 0;
+}
 
 /*
  * Reference a keymap from a keymapname.
diff --git a/Test/X03zlebindkey.ztst b/Test/X03zlebindkey.ztst
index d643b1ec9..3e299a337 100644
--- a/Test/X03zlebindkey.ztst
+++ b/Test/X03zlebindkey.ztst
@@ -141,3 +141,18 @@
 >CURSOR: 18
 >BUFFER: echo $(( ##x ) ##x ) y
 >CURSOR: 22
+
+  bindkey -d
+  for name in a b c d e; bindkey -N $name
+  bindkey -d
+  bindkey -l
+0:delete all keymaps after expanding keymapnamtab
+>.safe
+>command
+>emacs
+>isearch
+>main
+>vicmd
+>viins
+>viopp
+>visual