about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBart Schaefer <schaefer@zsh.org>2022-06-09 15:10:43 -0700
committerBart Schaefer <schaefer@zsh.org>2022-06-09 15:10:43 -0700
commit285b6c2538a3d5d427b13827679cb933a7e49c83 (patch)
tree8c17fd3a69c2d419a8eb048b0a55632303f92d41
parentd4955bc0f9403551503012c3f36c841210ce0cd5 (diff)
downloadzsh-285b6c2538a3d5d427b13827679cb933a7e49c83.tar.gz
zsh-285b6c2538a3d5d427b13827679cb933a7e49c83.tar.xz
zsh-285b6c2538a3d5d427b13827679cb933a7e49c83.zip
50363: avoid use of heap memory that depends on parameter scoping
-rw-r--r--ChangeLog5
-rw-r--r--Src/Modules/param_private.c12
2 files changed, 16 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index dc2ec1e89..2995844ae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2022-06-09  Bart Schaefer  <schaefer@zsh.org>
+
+	* 50363: Src/Modules/param_private.c: avoid use of heap memory
+	that depends on parameter scoping
+
 2022-06-09  Matthew Martin <phy1729@gmail.com>
 
 	* 50359: Src/builtin.c: fix bad sticky-emulation in "functions -c"
diff --git a/Src/Modules/param_private.c b/Src/Modules/param_private.c
index c53839152..065fa63d2 100644
--- a/Src/Modules/param_private.c
+++ b/Src/Modules/param_private.c
@@ -92,7 +92,7 @@ makeprivate(HashNode hn, UNUSED(int flags))
 	    makeprivate_error = 1;
 	    return;
 	}
-	struct gsu_closure *gsu = zhalloc(sizeof(struct gsu_closure));
+	struct gsu_closure *gsu = zalloc(sizeof(struct gsu_closure));
 	switch (PM_TYPE(pm->node.flags)) {
 	case PM_SCALAR:
 	    gsu->g = (void *)(pm->gsu.s);
@@ -269,6 +269,8 @@ pps_unsetfn(Param pm, int explicit)
 	gsu->unsetfn(pm, explicit);
     if (explicit)
 	pm->gsu.s = (GsuScalar)c;
+    else
+	zfree(c, sizeof(struct gsu_closure));
 }
 
 /**/
@@ -306,6 +308,8 @@ ppi_unsetfn(Param pm, int explicit)
 	gsu->unsetfn(pm, explicit);
     if (explicit)
 	pm->gsu.i = (GsuInteger)c;
+    else
+	zfree(c, sizeof(struct gsu_closure));
 }
 
 /**/
@@ -343,6 +347,8 @@ ppf_unsetfn(Param pm, int explicit)
 	gsu->unsetfn(pm, explicit);
     if (explicit)
 	pm->gsu.f = (GsuFloat)c;
+    else
+	zfree(c, sizeof(struct gsu_closure));
 }
 
 /**/
@@ -381,6 +387,8 @@ ppa_unsetfn(Param pm, int explicit)
 	gsu->unsetfn(pm, explicit);
     if (explicit)
 	pm->gsu.a = (GsuArray)c;
+    else
+	zfree(c, sizeof(struct gsu_closure));
 }
 
 static HashTable emptytable;
@@ -420,6 +428,8 @@ pph_unsetfn(Param pm, int explicit)
 	gsu->unsetfn(pm, explicit);
     if (explicit)
 	pm->gsu.h = (GsuHash)c;
+    else
+	zfree(c, sizeof(struct gsu_closure));
 }
 
 /*