Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug: zsh crashed when completing with pattern



> 2026/03/06 22:55、Jun. T <takimoto-j@xxxxxxxxxxxxxxxxx>のメール:

> I'm not sure whether zsh should issue an error or just consider 'nothing
> matches with a broken pattern’.

The patch below uses:
“issue an error” for module.c (zmodload -Fml), since it seems to be a rather common
behavior  of many builtins that support the option ‘-m’,
“nothing matches” for complete.c (compset -N), since it is the behavior of
‘compset -P’ and ‘compset -S’.

In complete.c, one PAT_STATIC is replaced by PAT_HEAPDUP (I think this was
missed in commit 6557aa4).


diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c
index 5152764b8..30effbcb4 100644
--- a/Src/Zle/complete.c
+++ b/Src/Zle/complete.c
@@ -965,7 +965,8 @@ do_comp_vars(int test, int na, char *sa, int nb, char *sb, int mod)
 		return 0;
 
 	    singsub(&sa);
-	    pp = patcompile(sa, PAT_HEAPDUP, NULL);
+	    if(!(pp = patcompile(sa, PAT_HEAPDUP, NULL)))
+		return 0;
 
 	    for (i--, p = compwords + i; i >= 0; p--, i--) {
 		if (pattry(pp, *p)) {
@@ -978,7 +979,8 @@ do_comp_vars(int test, int na, char *sa, int nb, char *sb, int mod)
 		int tt = 0;
 
 		singsub(&sb);
-		pp = patcompile(sb, PAT_STATIC, NULL);
+		if(!(pp = patcompile(sb, PAT_HEAPDUP, NULL)))
+		    return 0;
 
 		for (i++, p = compwords + i; i < l; p++, i++) {
 		    if (pattry(pp, *p)) {
diff --git a/Src/module.c b/Src/module.c
index 659bc3544..93e888d9e 100644
--- a/Src/module.c
+++ b/Src/module.c
@@ -3041,7 +3041,11 @@ bin_zmodload_features(const char *nam, char **args, Options ops)
 	    if (*arg == '+' || *arg == '-')
 		arg++;
 	    tokenize(arg);
-	    *patprogp = patcompile(arg, 0, 0);
+	    if(!(*patprogp = patcompile(arg, 0, 0))) {
+		untokenize(arg);
+		zwarnnam(nam, "bad pattern : %s", arg);
+		return 1;
+	    }
 	}
     } else
 	patprogs = NULL;







Messages sorted by: Reverse Date, Date, Thread, Author