From 3e72a52e27d8ce8d8be0ee65ae5f77f756c06fda Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Sun, 21 Dec 2025 12:46:04 +0900 Subject: 53959+54149: fix a bug when redirecting to a pattern with no match when redirecting to/from a pattern (MULTIOS) and if there is no match, issue an error even if NULL_GLOB is in effect. --- Src/glob.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'Src/glob.c') diff --git a/Src/glob.c b/Src/glob.c index 9bfb0f895..e13481955 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -1202,6 +1202,9 @@ checkglobqual(char *str, int sl, int nobareglob, char **sp) return ret; } +/* notify zglob() that it is called from expandredir() */ +static int in_expandredir = 0; + /* Main entry point to the globbing code for filename globbing. * * np points to a node in the list which will be expanded * * into a series of nodes. */ @@ -1882,6 +1885,14 @@ zglob(LinkList list, LinkNode np, int nountok) matchct = 1; } } + else if (in_expandredir) { + /* if completing for redirection, we can't remove the pattern + * even if NULL_GLOB is in effect */ + zerr("redirection failed (no match): %s", ostr); + zfree(matchbuf, 0); + restore_globstate(saved); + return; + } if (!(gf_sortlist[0].tp & GS_NONE)) { /* @@ -2148,8 +2159,11 @@ xpandredir(struct redir *fn, LinkList redirtab) /* ...which undergoes all the usual shell expansions */ prefork(&fake, isset(MULTIOS) ? 0 : PREFORK_SINGLE, NULL); /* Globbing is only done for multios. */ - if (!errflag && isset(MULTIOS)) + if (!errflag && isset(MULTIOS)) { + in_expandredir = 1; globlist(&fake, 0); + in_expandredir = 0; + } if (errflag) return 0; if (nonempty(&fake) && !nextnode(firstnode(&fake))) { -- cgit v1.2.3-70-g09d2