aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2012-01-14 15:09:15 +0800
committerChong Yidong2012-01-14 15:09:15 +0800
commit9e5788aaef98e88aeb5b2476549f72b591e0bf4a (patch)
tree25ea16ea3195d9c928cab55f144d4a60906e80c0
parent3cdb7f5a3854515902553934d2a9886781c5e56f (diff)
downloademacs-9e5788aaef98e88aeb5b2476549f72b591e0bf4a.tar.gz
emacs-9e5788aaef98e88aeb5b2476549f72b591e0bf4a.zip
Fix race condition in epg.el compat code.
* lisp/epg.el (epg--make-temp-file): Avoid permission race condition when running on old Emacs versions. Fixes: debbugs:10403
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/epg.el7
2 files changed, 9 insertions, 3 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 98312d64853..968e2f91996 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
12012-01-14 Paul Eggert <eggert@cs.ucla.edu>
2
3 * epg.el (epg--make-temp-file): Avoid permission race condition
4 when running on old Emacs versions (bug#10403).
5
12012-01-14 Glenn Morris <rgm@gnu.org> 62012-01-14 Glenn Morris <rgm@gnu.org>
2 7
3 * dired.el (dired-get-filename): Fix 'verbatim case of previous change. 8 * dired.el (dired-get-filename): Fix 'verbatim case of previous change.
diff --git a/lisp/epg.el b/lisp/epg.el
index 3505e183c1f..6529afb2d3c 100644
--- a/lisp/epg.el
+++ b/lisp/epg.el
@@ -1951,7 +1951,8 @@ The returned file name (created by appending some random characters at the end
1951of PREFIX, and expanding against `temporary-file-directory' if necessary), 1951of PREFIX, and expanding against `temporary-file-directory' if necessary),
1952is guaranteed to point to a newly created empty file. 1952is guaranteed to point to a newly created empty file.
1953You can then use `write-region' to write new data into the file." 1953You can then use `write-region' to write new data into the file."
1954 (let (tempdir tempfile) 1954 (let ((orig-modes (default-file-modes))
1955 tempdir tempfile)
1955 (setq prefix (expand-file-name prefix 1956 (setq prefix (expand-file-name prefix
1956 (if (featurep 'xemacs) 1957 (if (featurep 'xemacs)
1957 (temp-directory) 1958 (temp-directory)
@@ -1959,6 +1960,7 @@ You can then use `write-region' to write new data into the file."
1959 (unwind-protect 1960 (unwind-protect
1960 (let (file) 1961 (let (file)
1961 ;; First, create a temporary directory. 1962 ;; First, create a temporary directory.
1963 (set-default-file-modes #o700)
1962 (while (condition-case () 1964 (while (condition-case ()
1963 (progn 1965 (progn
1964 (setq tempdir (make-temp-name 1966 (setq tempdir (make-temp-name
@@ -1969,14 +1971,12 @@ You can then use `write-region' to write new data into the file."
1969 (make-directory tempdir)) 1971 (make-directory tempdir))
1970 ;; let's try again. 1972 ;; let's try again.
1971 (file-already-exists t))) 1973 (file-already-exists t)))
1972 (set-file-modes tempdir 448)
1973 ;; Second, create a temporary file in the tempdir. 1974 ;; Second, create a temporary file in the tempdir.
1974 ;; There *is* a race condition between `make-temp-name' 1975 ;; There *is* a race condition between `make-temp-name'
1975 ;; and `write-region', but we don't care it since we are 1976 ;; and `write-region', but we don't care it since we are
1976 ;; in a private directory now. 1977 ;; in a private directory now.
1977 (setq tempfile (make-temp-name (concat tempdir "/EMU"))) 1978 (setq tempfile (make-temp-name (concat tempdir "/EMU")))
1978 (write-region "" nil tempfile nil 'silent) 1979 (write-region "" nil tempfile nil 'silent)
1979 (set-file-modes tempfile 384)
1980 ;; Finally, make a hard-link from the tempfile. 1980 ;; Finally, make a hard-link from the tempfile.
1981 (while (condition-case () 1981 (while (condition-case ()
1982 (progn 1982 (progn
@@ -1986,6 +1986,7 @@ You can then use `write-region' to write new data into the file."
1986 ;; let's try again. 1986 ;; let's try again.
1987 (file-already-exists t))) 1987 (file-already-exists t)))
1988 file) 1988 file)
1989 (set-default-file-modes orig-modes)
1989 ;; Cleanup the tempfile. 1990 ;; Cleanup the tempfile.
1990 (and tempfile 1991 (and tempfile
1991 (file-exists-p tempfile) 1992 (file-exists-p tempfile)