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

[PATCH] make sure internal temp files are user readable and writeable



Here-documents fail if the umask does not allow user reading.

$ zsh -c $'umask u-r; cat <<EOF\nEOF'
zsh:1: can't create temp file for here document: permission denied

Silly though 'umask u-r' may be, the fact that here-documents use
temporary files on zsh is an internal implementation detail that should
make no difference to the script. It is trivial to save and temporarily
fix the umask during the creation of the temporary file.

This may fix a few other things that use gettempfile() as well.

- M.
diff --git a/Src/utils.c b/Src/utils.c
index 6517e15..a9c6231 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -2177,6 +2177,7 @@ gettempfile(const char *prefix, int use_heap, char **tempname)
 {
     char *fn;
     int fd;
+    mode_t old_umask = umask(0177);
 #if HAVE_MKSTEMP
     char *suffix = prefix ? ".XXXXXX" : "XXXXXX";
 
@@ -2212,6 +2213,7 @@ gettempfile(const char *prefix, int use_heap, char **tempname)
 #endif
     *tempname = fn;
 
+    umask(old_umask);
     unqueue_signals();
     return fd;
 }
diff --git a/Test/A04redirect.ztst b/Test/A04redirect.ztst
index ef7ddb2..b5b65cf 100644
--- a/Test/A04redirect.ztst
+++ b/Test/A04redirect.ztst
@@ -667,3 +667,12 @@
 0:Redirect in the middle of assignments
 >b
 >d
+
+  umask 0777
+  cat <<'  HERE'
+  look ma, no permissions
+  HERE
+  cat <<<"it's a miracle"
+0:Here-{string,document}s succeed with restrictive umask
+>  look ma, no permissions
+>it's a miracle


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