about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2014-09-29 17:17:26 +0100
committerPeter Stephenson <pws@zsh.org>2014-09-29 17:17:26 +0100
commitf2aaea5cd31fcca6f060e1de0cb1e91c05c716bb (patch)
treed9fa45066808a4aadb1bb633f3f4d0c68c3bbac0
parent546203a770cec329e73781c3c8ab1078390aee72 (diff)
downloadzsh-f2aaea5cd31fcca6f060e1de0cb1e91c05c716bb.tar.gz
zsh-f2aaea5cd31fcca6f060e1de0cb1e91c05c716bb.tar.xz
zsh-f2aaea5cd31fcca6f060e1de0cb1e91c05c716bb.zip
users/19183: improve unlikely error case with fdopen in history code
-rw-r--r--ChangeLog3
-rw-r--r--Src/hist.c7
2 files changed, 9 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index dba06e479..f1fb73ed0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2014-09-29  Peter Stephenson  <p.stephenson@samsung.com>
 
+	* users/19183: Src/hist.c: handle unlikely error case with
+	fdopen() better.
+
 	* 33276: Src/params.c, Src/zsh.h: safer import of numerical
 	variables from environment.
 
diff --git a/Src/hist.c b/Src/hist.c
index d29a65afe..4660fd073 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -2593,7 +2593,12 @@ savehistfile(char *fn, int err, int writeflags)
 		out = NULL;
 	    } else {
 		int fd = open(tmpfile, O_CREAT | O_WRONLY | O_EXCL, 0600);
-		out = fd >= 0 ? fdopen(fd, "w") : NULL;
+		if (fd >=0) {
+		    out = fdopen(fd, "w");
+		    if (!out)
+			close(fd);
+		} else
+		    out = NULL;
 	    }
 
 #ifdef HAVE_FCHMOD