summaryrefslogtreecommitdiff
path: root/lisp/epg.el
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2011-12-29 14:08:29 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2011-12-29 14:08:29 -0800
commitdbf17d8b483f08f9506c19ef95e894fca62b8ec7 (patch)
tree3bcbabd58ddbaf89feafedadd12a6c08adbe210b /lisp/epg.el
parenta0562b3d54b898ea9da9359b16ec1fd7ec4f16d6 (diff)
downloademacs-dbf17d8b483f08f9506c19ef95e894fca62b8ec7.tar.gz
* epg.el (epg--make-temp-file): Avoid permission race conditions
when creating temporary directories and files on older Emacs.
Diffstat (limited to 'lisp/epg.el')
-rw-r--r--lisp/epg.el7
1 files changed, 4 insertions, 3 deletions
diff --git a/lisp/epg.el b/lisp/epg.el
index 133e76da96c..8e784257d54 100644
--- a/lisp/epg.el
+++ b/lisp/epg.el
@@ -1951,14 +1951,16 @@ The returned file name (created by appending some random characters at the end
of PREFIX, and expanding against `temporary-file-directory' if necessary),
is guaranteed to point to a newly created empty file.
You can then use `write-region' to write new data into the file."
- (let (tempdir tempfile)
+ (let (tempdir tempfile orig-modes)
(setq prefix (expand-file-name prefix
(if (featurep 'xemacs)
(temp-directory)
temporary-file-directory)))
+ (setq orig-modes (default-file-modes))
(unwind-protect
(let (file)
;; First, create a temporary directory.
+ (set-default-file-modes #o700)
(while (condition-case ()
(progn
(setq tempdir (make-temp-name
@@ -1969,14 +1971,12 @@ You can then use `write-region' to write new data into the file."
(make-directory tempdir))
;; let's try again.
(file-already-exists t)))
- (set-file-modes tempdir 448)
;; Second, create a temporary file in the tempdir.
;; There *is* a race condition between `make-temp-name'
;; and `write-region', but we don't care it since we are
;; in a private directory now.
(setq tempfile (make-temp-name (concat tempdir "/EMU")))
(write-region "" nil tempfile nil 'silent)
- (set-file-modes tempfile 384)
;; Finally, make a hard-link from the tempfile.
(while (condition-case ()
(progn
@@ -1986,6 +1986,7 @@ You can then use `write-region' to write new data into the file."
;; let's try again.
(file-already-exists t)))
file)
+ (set-default-file-modes orig-modes)
;; Cleanup the tempfile.
(and tempfile
(file-exists-p tempfile)