Blame SOURCES/0001-patch-8.2.4253-using-freed-memory-when-substitute-wi.patch

b6500d
commit c604f3ad4782fde770617ff688e1ceac0dc1bd7c
b6500d
Author: Tomas Korbar <tkorbar@redhat.com>
b6500d
Date:   Thu Feb 3 10:14:42 2022 +0100
b6500d
b6500d
    Fix using freed memory when substitute with function call
b6500d
b6500d
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
b6500d
index e69fbd3..0788573 100644
b6500d
--- a/src/ex_cmds.c
b6500d
+++ b/src/ex_cmds.c
b6500d
@@ -4767,6 +4767,7 @@ do_sub(exarg_T *eap)
b6500d
     int		save_do_all;		/* remember user specified 'g' flag */
b6500d
     int		save_do_ask;		/* remember user specified 'c' flag */
b6500d
     char_u	*pat = NULL, *sub = NULL;	/* init for GCC */
b6500d
+	char_u	*sub_copy = NULL;
b6500d
     int		delimiter;
b6500d
     int		sublen;
b6500d
     int		got_quit = FALSE;
b6500d
@@ -5062,11 +5063,20 @@ do_sub(exarg_T *eap)
b6500d
     sub_firstline = NULL;
b6500d
 
b6500d
     /*
b6500d
-     * ~ in the substitute pattern is replaced with the old pattern.
b6500d
-     * We do it here once to avoid it to be replaced over and over again.
b6500d
-     * But don't do it when it starts with "\=", then it's an expression.
b6500d
+     * If the substitute pattern starts with "\=" then it's an expression.
b6500d
+     * Make a copy, a recursive function may free it.
b6500d
+     * Otherwise, '~' in the substitute pattern is replaced with the old
b6500d
+     * pattern.  We do it here once to avoid it to be replaced over and over
b6500d
+     * again.
b6500d
      */
b6500d
-    if (!(sub[0] == '\\' && sub[1] == '='))
b6500d
+    if (sub[0] == '\\' && sub[1] == '=')
b6500d
+    {
b6500d
+	sub = vim_strsave(sub);
b6500d
+	if (sub == NULL)
b6500d
+	    return;
b6500d
+	sub_copy = sub;
b6500d
+    }
b6500d
+    else
b6500d
 	sub = regtilde(sub, p_magic);
b6500d
 
b6500d
     /*
b6500d
@@ -5825,6 +5835,7 @@ outofmem:
b6500d
 #endif
b6500d
 
b6500d
     vim_regfree(regmatch.regprog);
b6500d
+	vim_free(sub_copy);
b6500d
 
b6500d
     /* Restore the flag values, they can be used for ":&&". */
b6500d
     subflags.do_all = save_do_all;