On 11.3. 17:17, Stephane Chazelas wrote:
$ bash -c 'umask 400; cat <<< test'
bash: cannot create temp file for here-document: Permission denied

Those shells use temporary files to store the content of the
here-documents as the Bourne shell initially did, and open them
in read-only mode to make it cat's stdin.

When umask contains the 0400 bit, the file is created without
read permission to the user, hence the error upon that second
open().
I can think of several ways to address it:

1- do nothing and blame the user
2- open the file only once for both
writing the content and making it the command's stdin
3. use a pipe instead of a temp file
4. Reset the umask temporarily to 077

One more came to mind:

5. manually chmod() the tempfile to 0400 or 0600 if the open() for reading fails with EACCES, and then retry. Should be doable with a localized change to that particular error condition, without changing the overall behaviour.

2 would have my preference.



--
Ilkka Virta / itvi...@iki.fi

Reply via email to