summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorMikael Magnusson <mikachu@gmail.com>2015-02-10 07:54:18 +0100
committerMikael Magnusson <mikachu@gmail.com>2015-02-10 13:03:49 +0100
commit2dbbc88d0b78c3fc2fb8e63fba67119c5aa456fc (patch)
tree216872dc6fe3d367afcec38da0fdc0c4db3c6912 /Src
parentda86d6b4f2c3eef5b1f0860c9dae433f3a540951 (diff)
downloadzsh-2dbbc88d0b78c3fc2fb8e63fba67119c5aa456fc.tar.gz
zsh-2dbbc88d0b78c3fc2fb8e63fba67119c5aa456fc.tar.xz
zsh-2dbbc88d0b78c3fc2fb8e63fba67119c5aa456fc.zip
34488: Fix use-after-free for print -zf and print -sf
Diffstat (limited to 'Src')
-rw-r--r--Src/builtin.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index 08be1acdd..e093cbe32 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -4527,7 +4527,8 @@ bin_print(char *name, char **args, Options ops, int func)
     if (OPT_ISSET(ops,'z') || OPT_ISSET(ops,'s')) {
 #ifdef HAVE_OPEN_MEMSTREAM
 	putc(0, fout);
-	fflush(fout);
+	fclose(fout);
+	fout = NULL;
 #else
 	rewind(fout);
 	buf = (char *)zalloc(count + 1);
@@ -4548,11 +4549,16 @@ bin_print(char *name, char **args, Options ops, int func)
 	unqueue_signals();
     }
 
-    /* Testing EBADF special-cases >&- redirections */
-    if ((fout != stdout) ? (fclose(fout) != 0) :
-	(fflush(fout) != 0 && errno != EBADF)) {
-	zwarnnam(name, "write error: %e", errno);
-	ret = 1;
+#ifdef HAVE_OPEN_MEMSTREAM
+    if (fout)
+#endif
+    {
+	/* Testing EBADF special-cases >&- redirections */
+	if ((fout != stdout) ? (fclose(fout) != 0) :
+	    (fflush(fout) != 0 && errno != EBADF)) {
+	    zwarnnam(name, "write error: %e", errno);
+	    ret = 1;
+	}
     }
     return ret;
 }