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

PATCH: Fix 49658 more



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





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