emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r106861: Fix race condition in epg.el


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r106861: Fix race condition in epg.el compat code.
Date: Sat, 14 Jan 2012 15:09:15 +0800
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 106861
fixes bug(s): http://debbugs.gnu.org/10403
author: Paul Eggert <address@hidden>
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Sat 2012-01-14 15:09:15 +0800
message:
  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.
modified:
  lisp/ChangeLog
  lisp/epg.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-01-14 02:07:49 +0000
+++ b/lisp/ChangeLog    2012-01-14 07:09:15 +0000
@@ -1,3 +1,8 @@
+2012-01-14  Paul Eggert  <address@hidden>
+
+       * epg.el (epg--make-temp-file): Avoid permission race condition
+       when running on old Emacs versions (bug#10403).
+
 2012-01-14  Glenn Morris  <address@hidden>
 
        * dired.el (dired-get-filename): Fix 'verbatim case of previous change.

=== modified file 'lisp/epg.el'
--- a/lisp/epg.el       2012-01-07 19:58:55 +0000
+++ b/lisp/epg.el       2012-01-14 07:09:15 +0000
@@ -1951,7 +1951,8 @@
 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 ((orig-modes (default-file-modes))
+           tempdir tempfile)
        (setq prefix (expand-file-name prefix
                                       (if (featurep 'xemacs)
                                           (temp-directory)
@@ -1959,6 +1960,7 @@
        (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 @@
                           (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 @@
                       ;; let's try again.
                       (file-already-exists t)))
              file)
+         (set-default-file-modes orig-modes)
          ;; Cleanup the tempfile.
          (and tempfile
               (file-exists-p tempfile)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]