aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/ChangeLog3
-rw-r--r--lisp/epg.el7
2 files changed, 7 insertions, 3 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2c1d59d45a5..ba05002cc69 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,8 @@
12011-12-29 Paul Eggert <eggert@cs.ucla.edu> 12011-12-29 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 * epg.el (epg--make-temp-file): Avoid permission race conditions
4 when creating temporary directories and files on older Emacs.
5
3 * files.el (move-file-to-trash): Preserve default file modes on error. 6 * files.el (move-file-to-trash): Preserve default file modes on error.
4 (Bug#10401) 7 (Bug#10401)
5 8
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
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 (tempdir tempfile orig-modes)
1955 (setq prefix (expand-file-name prefix 1955 (setq prefix (expand-file-name prefix
1956 (if (featurep 'xemacs) 1956 (if (featurep 'xemacs)
1957 (temp-directory) 1957 (temp-directory)
1958 temporary-file-directory))) 1958 temporary-file-directory)))
1959 (setq orig-modes (default-file-modes))
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)