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
committerdana <dana@dana.is>2022-02-12 07:22:15 -0600
commit9d20469c030ead700959fa3b95d7bc85bb9578a8 (patch)
tree880f4a1fe4fb9cb4d9bf34180846be4616c91353
parentf2ae864016340aed35270502aedbad6da9e6f1bf (diff)
downloadzsh-9d20469c030ead700959fa3b95d7bc85bb9578a8.tar.gz
zsh-9d20469c030ead700959fa3b95d7bc85bb9578a8.tar.xz
zsh-9d20469c030ead700959fa3b95d7bc85bb9578a8.zip
49377: fix segfault by 'bindkey -d' with reordered keymapnamtab
(cherry picked from commit 2a7945a900c8a1b1866ad31ee5e95db5b0ddb50a)
-rw-r--r--ChangeLog4
-rw-r--r--Src/Zle/zle_keymap.c22
-rw-r--r--Test/X03zlebindkey.ztst15
3 files changed, 40 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index b7721e856..7136b210a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2022-01-27  dana  <dana@dana.is>
 
+	* Jun-ichi Takimoto: 49377: Src/Zle/zle_keymap.c,
+	Test/X03zlebindkey.ztst: fix segfault by 'bindkey -d' with
+	reordered keymapnamtab
+
 	* Jun-ichi Takimoto: 47560: configure.ac, aczsh.m4: add necessary
 	includes or prototypes for the tests in configure (fix errors in
 	macOS 11)
diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c
index d13aed594..49b2a26ad 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 298d7df5d..e5aac7379 100644
--- a/Test/X03zlebindkey.ztst
+++ b/Test/X03zlebindkey.ztst
@@ -143,3 +143,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