about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBart Schaefer <schaefer@zsh.org>2023-02-26 18:54:10 -0800
committerBart Schaefer <schaefer@zsh.org>2023-02-26 18:54:10 -0800
commitec4bd3169d0734ca8ec74ccc52235e71d7e59166 (patch)
treed9ecc6c872157f145f2d8cf3590aac82e11163ff
parentd76004588b26c179893431122ebfe064d58cf907 (diff)
downloadzsh-ec4bd3169d0734ca8ec74ccc52235e71d7e59166.tar.gz
zsh-ec4bd3169d0734ca8ec74ccc52235e71d7e59166.tar.xz
zsh-ec4bd3169d0734ca8ec74ccc52235e71d7e59166.zip
51460: avoid crash on bad parameter autofeature
-rw-r--r--ChangeLog4
-rw-r--r--Src/module.c17
2 files changed, 15 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 1891b8b5a..2c07606c5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2023-02-26  Bart Schaefer  <schaefer@zsh.org>
+
+	* 51460: Src/module.c: avoid crash on bad parameter autofeature
+
 2023-02-24  Oliver Kiddle  <opk@zsh.org>
 
 	* Shohei YOSHIDA: 51473: Completion/Unix/Command/_cal:
diff --git a/Src/module.c b/Src/module.c
index 6cf442270..a6005f30b 100644
--- a/Src/module.c
+++ b/Src/module.c
@@ -1198,6 +1198,7 @@ add_autoparam(const char *module, const char *pnam, int flags)
 {
     Param pm;
     int ret;
+    int ne = noerrs;
 
     queue_signals();
     if ((ret = checkaddparam(pnam, (flags & FEAT_IGNORE)))) {
@@ -1212,14 +1213,18 @@ add_autoparam(const char *module, const char *pnam, int flags)
 	return ret == 2 ? 0 : -1;
     }
 
-    pm = setsparam(dupstring(pnam), ztrdup(module));
-
-    pm->node.flags |= PM_AUTOLOAD;
-    if (flags & FEAT_AUTOALL)
-	pm->node.flags |= PM_AUTOALL;
+    noerrs = 2;
+    if ((pm = setsparam(dupstring(pnam), ztrdup(module)))) {
+	pm->node.flags |= PM_AUTOLOAD;
+	if (flags & FEAT_AUTOALL)
+	    pm->node.flags |= PM_AUTOALL;
+	ret = 0;
+    } else
+	ret = -1;
+    noerrs = ne;
     unqueue_signals();
 
-    return 0;
+    return ret;
 }
 
 /* Remove a parameter added with add_autoparam() */