zsh-workers
 help / color / mirror / code / Atom feed
From: Martijn Dekker <martijn@inlv.org>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] make sure internal temp files are user readable and writeable
Date: Mon, 26 Mar 2018 18:45:23 +0200	[thread overview]
Message-ID: <581009fe-372c-641a-cf5f-87e6a2a68dbb@inlv.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 507 bytes --]

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.

[-- Attachment #2: heredoc-umask.patch --]
[-- Type: text/plain, Size: 925 bytes --]

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

             reply	other threads:[~2018-03-26 16:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-26 16:45 Martijn Dekker [this message]
2018-03-26 17:00 ` Stephane Chazelas
2018-03-26 17:37   ` Martijn Dekker
2018-03-26 20:32     ` Martijn Dekker
2018-03-27  8:34       ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=581009fe-372c-641a-cf5f-87e6a2a68dbb@inlv.org \
    --to=martijn@inlv.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).