zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Fix 49658 more
@ 2022-03-19  0:33 Mikael Magnusson
  0 siblings, 0 replies; only message in thread
From: Mikael Magnusson @ 2022-03-19  0:33 UTC (permalink / raw)
  To: zsh-workers

Revert "49658: Fix NULL reference in match code."

This reverts commit 7f240e6aa9f5596a129474ba6294875dfe7ae264.

The above commit causes a crash due to ll being calculated as 0 which
leads to rr being an invalid pointer. Only fixing that to return NULL
when ll is 0 just leads to bck-i-search pattern not working at all,
restoring the condition and adding an explicit NULL check for replstr
seems to work for me.
---
 Src/glob.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/Src/glob.c b/Src/glob.c
index e31843ad09..aa43253db3 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -2599,7 +2599,7 @@ get_match_ret(Imatchdata imd, int b, int e)
     e += add;
 
     /* Everything now refers to metafied lengths. */
-    if (replstr) {
+    if (replstr || (fl & SUB_LIST)) {
 	if (fl & SUB_DOSUBST) {
 	    replstr = dupstring(replstr);
 	    singsub(&replstr);
@@ -2618,7 +2618,8 @@ get_match_ret(Imatchdata imd, int b, int e)
 		addlinknode(imd->repllist, rd);
 	    return imd->mstr;
 	}
-	ll += strlen(replstr);
+	if (replstr)
+	    ll += strlen(replstr);
     }
     if (fl & SUB_MATCH)			/* matched portion */
 	ll += 1 + (e - b);
@@ -2644,6 +2645,9 @@ get_match_ret(Imatchdata imd, int b, int e)
     if (bl)
 	buf[bl - 1] = '\0';
 
+    if (ll == 0)
+	return NULL;
+
     rr = r = (char *) hcalloc(ll);
 
     if (fl & SUB_MATCH) {
-- 
2.15.1



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-19  0:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-19  0:33 PATCH: Fix 49658 more Mikael Magnusson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).