diff options
| author | Paul Eggert | 2020-02-19 13:47:57 -0800 |
|---|---|---|
| committer | Paul Eggert | 2020-02-19 13:48:27 -0800 |
| commit | 734eb7e457da8a9b2c91798d591c03285c6967ce (patch) | |
| tree | c8d8dc92d4af164c895d73de29e3d548385cff3c | |
| parent | 4b118bdca1d8aa130fb67eadb16e08e87e698aa4 (diff) | |
| download | emacs-734eb7e457da8a9b2c91798d591c03285c6967ce.tar.gz emacs-734eb7e457da8a9b2c91798d591c03285c6967ce.zip | |
Fix some file-modes races
* lisp/gnus/gnus-start.el (gnus-save-newsrc-file)
(gnus-slave-save-newsrc):
* lisp/gnus/gnus-uu.el (gnus-uu-initialize):
* lisp/gnus/mm-archive.el (mm-dissect-archive):
* lisp/gnus/mm-decode.el (mm-temp-files-delete)
(mm-display-external):
* lisp/image-dired.el (image-dired-create-thumb-1):
Use with-file-modes rather than setting the file modes later.
This fixes some race conditions where the file temporarily
has the wrong permissions.
| -rw-r--r-- | lisp/gnus/gnus-start.el | 22 | ||||
| -rw-r--r-- | lisp/gnus/gnus-uu.el | 4 | ||||
| -rw-r--r-- | lisp/gnus/mm-archive.el | 5 | ||||
| -rw-r--r-- | lisp/gnus/mm-decode.el | 18 | ||||
| -rw-r--r-- | lisp/image-dired.el | 4 |
5 files changed, 26 insertions, 27 deletions
diff --git a/lisp/gnus/gnus-start.el b/lisp/gnus/gnus-start.el index 1fd2575ea1f..873923e6c57 100644 --- a/lisp/gnus/gnus-start.el +++ b/lisp/gnus/gnus-start.el | |||
| @@ -2812,7 +2812,7 @@ values from `gnus-newsrc-hashtb', and write a new value of | |||
| 2812 | (file-exists-p working-file))) | 2812 | (file-exists-p working-file))) |
| 2813 | 2813 | ||
| 2814 | (unwind-protect | 2814 | (unwind-protect |
| 2815 | (progn | 2815 | (with-file-modes (file-modes startup-file) |
| 2816 | (gnus-with-output-to-file working-file | 2816 | (gnus-with-output-to-file working-file |
| 2817 | (gnus-gnus-to-quick-newsrc-format) | 2817 | (gnus-gnus-to-quick-newsrc-format) |
| 2818 | (gnus-run-hooks 'gnus-save-quick-newsrc-hook)) | 2818 | (gnus-run-hooks 'gnus-save-quick-newsrc-hook)) |
| @@ -2822,14 +2822,12 @@ values from `gnus-newsrc-hashtb', and write a new value of | |||
| 2822 | ;; file. | 2822 | ;; file. |
| 2823 | (let ((buffer-backed-up nil) | 2823 | (let ((buffer-backed-up nil) |
| 2824 | (buffer-file-name startup-file) | 2824 | (buffer-file-name startup-file) |
| 2825 | (file-precious-flag t) | 2825 | (file-precious-flag t)) |
| 2826 | (setmodes (file-modes startup-file))) | ||
| 2827 | ;; Backup the current version of the startup file. | 2826 | ;; Backup the current version of the startup file. |
| 2828 | (backup-buffer) | 2827 | (backup-buffer) |
| 2829 | 2828 | ||
| 2830 | ;; Replace the existing startup file with the temp file. | 2829 | ;; Replace the existing startup file with the temp file. |
| 2831 | (rename-file working-file startup-file t) | 2830 | (rename-file working-file startup-file t) |
| 2832 | (gnus-set-file-modes startup-file setmodes) | ||
| 2833 | (setq gnus-save-newsrc-file-last-timestamp | 2831 | (setq gnus-save-newsrc-file-last-timestamp |
| 2834 | (file-attribute-modification-time | 2832 | (file-attribute-modification-time |
| 2835 | (file-attributes startup-file))))) | 2833 | (file-attributes startup-file))))) |
| @@ -3004,14 +3002,14 @@ SPECIFIC-VARIABLES, or those in `gnus-variable-list'." | |||
| 3004 | 3002 | ||
| 3005 | (defun gnus-slave-save-newsrc () | 3003 | (defun gnus-slave-save-newsrc () |
| 3006 | (with-current-buffer gnus-dribble-buffer | 3004 | (with-current-buffer gnus-dribble-buffer |
| 3007 | (let ((slave-name | 3005 | (with-file-modes (or (ignore-errors |
| 3008 | (make-temp-file (concat gnus-current-startup-file "-slave-"))) | 3006 | (file-modes |
| 3009 | (modes (ignore-errors | 3007 | (concat gnus-current-startup-file ".eld"))) |
| 3010 | (file-modes (concat gnus-current-startup-file ".eld"))))) | 3008 | (default-file-modes)) |
| 3011 | (let ((coding-system-for-write gnus-ding-file-coding-system)) | 3009 | (let ((slave-name |
| 3012 | (gnus-write-buffer slave-name)) | 3010 | (make-temp-file (concat gnus-current-startup-file "-slave-")))) |
| 3013 | (when modes | 3011 | (let ((coding-system-for-write gnus-ding-file-coding-system)) |
| 3014 | (gnus-set-file-modes slave-name modes))))) | 3012 | (gnus-write-buffer slave-name)))))) |
| 3015 | 3013 | ||
| 3016 | (defun gnus-master-read-slave-newsrc () | 3014 | (defun gnus-master-read-slave-newsrc () |
| 3017 | (let ((slave-files | 3015 | (let ((slave-files |
diff --git a/lisp/gnus/gnus-uu.el b/lisp/gnus/gnus-uu.el index d40ba9cef42..4037221f496 100644 --- a/lisp/gnus/gnus-uu.el +++ b/lisp/gnus/gnus-uu.el | |||
| @@ -1781,8 +1781,8 @@ Gnus might fail to display all of it.") | |||
| 1781 | gnus-uu-tmp-dir))) | 1781 | gnus-uu-tmp-dir))) |
| 1782 | 1782 | ||
| 1783 | (setq gnus-uu-work-dir | 1783 | (setq gnus-uu-work-dir |
| 1784 | (make-temp-file (concat gnus-uu-tmp-dir "gnus") 'dir)) | 1784 | (with-file-modes #o700 |
| 1785 | (gnus-set-file-modes gnus-uu-work-dir 448) | 1785 | (make-temp-file (concat gnus-uu-tmp-dir "gnus") 'dir))) |
| 1786 | (setq gnus-uu-work-dir (file-name-as-directory gnus-uu-work-dir)) | 1786 | (setq gnus-uu-work-dir (file-name-as-directory gnus-uu-work-dir)) |
| 1787 | (push (cons gnus-newsgroup-name gnus-uu-work-dir) | 1787 | (push (cons gnus-newsgroup-name gnus-uu-work-dir) |
| 1788 | gnus-uu-tmp-alist)))) | 1788 | gnus-uu-tmp-alist)))) |
diff --git a/lisp/gnus/mm-archive.el b/lisp/gnus/mm-archive.el index 71676c12a46..56253afa193 100644 --- a/lisp/gnus/mm-archive.el +++ b/lisp/gnus/mm-archive.el | |||
| @@ -42,8 +42,9 @@ | |||
| 42 | dir) | 42 | dir) |
| 43 | (unless decoder | 43 | (unless decoder |
| 44 | (error "No decoder found for %s" type)) | 44 | (error "No decoder found for %s" type)) |
| 45 | (setq dir (make-temp-file (expand-file-name "emm." mm-tmp-directory) 'dir)) | 45 | (with-file-modes #o700 |
| 46 | (set-file-modes dir #o700) | 46 | (setq dir (make-temp-file (expand-file-name "emm." mm-tmp-directory) |
| 47 | 'dir))) | ||
| 47 | (unwind-protect | 48 | (unwind-protect |
| 48 | (progn | 49 | (progn |
| 49 | (mm-with-unibyte-buffer | 50 | (mm-with-unibyte-buffer |
diff --git a/lisp/gnus/mm-decode.el b/lisp/gnus/mm-decode.el index d33bb56dc9e..2dab278b373 100644 --- a/lisp/gnus/mm-decode.el +++ b/lisp/gnus/mm-decode.el | |||
| @@ -602,11 +602,10 @@ files left at the next time." | |||
| 602 | (push temp fails))) | 602 | (push temp fails))) |
| 603 | (if fails | 603 | (if fails |
| 604 | ;; Schedule the deletion of the files left at the next time. | 604 | ;; Schedule the deletion of the files left at the next time. |
| 605 | (progn | 605 | (with-file-modes #o600 |
| 606 | (write-region (concat (mapconcat 'identity (nreverse fails) "\n") | 606 | (write-region (concat (mapconcat 'identity (nreverse fails) "\n") |
| 607 | "\n") | 607 | "\n") |
| 608 | nil cache-file nil 'silent) | 608 | nil cache-file nil 'silent)) |
| 609 | (set-file-modes cache-file #o600)) | ||
| 610 | (when (file-exists-p cache-file) | 609 | (when (file-exists-p cache-file) |
| 611 | (ignore-errors (delete-file cache-file)))) | 610 | (ignore-errors (delete-file cache-file)))) |
| 612 | (setq mm-temp-files-to-be-deleted nil))) | 611 | (setq mm-temp-files-to-be-deleted nil))) |
| @@ -911,8 +910,10 @@ external if displayed external." | |||
| 911 | ;; The function is a string to be executed. | 910 | ;; The function is a string to be executed. |
| 912 | (mm-insert-part handle) | 911 | (mm-insert-part handle) |
| 913 | (mm-add-meta-html-tag handle) | 912 | (mm-add-meta-html-tag handle) |
| 914 | (let* ((dir (make-temp-file | 913 | ;; We create a private sub-directory where we store our files. |
| 915 | (expand-file-name "emm." mm-tmp-directory) 'dir)) | 914 | (let* ((dir (with-file-modes #o700 |
| 915 | (make-temp-file | ||
| 916 | (expand-file-name "emm." mm-tmp-directory) 'dir))) | ||
| 916 | (filename (or | 917 | (filename (or |
| 917 | (mail-content-type-get | 918 | (mail-content-type-get |
| 918 | (mm-handle-disposition handle) 'filename) | 919 | (mm-handle-disposition handle) 'filename) |
| @@ -924,8 +925,6 @@ external if displayed external." | |||
| 924 | (assoc "needsterminal" mime-info))) | 925 | (assoc "needsterminal" mime-info))) |
| 925 | (copiousoutput (assoc "copiousoutput" mime-info)) | 926 | (copiousoutput (assoc "copiousoutput" mime-info)) |
| 926 | file buffer) | 927 | file buffer) |
| 927 | ;; We create a private sub-directory where we store our files. | ||
| 928 | (set-file-modes dir #o700) | ||
| 929 | (if filename | 928 | (if filename |
| 930 | (setq file (expand-file-name | 929 | (setq file (expand-file-name |
| 931 | (gnus-map-function mm-file-name-rewrite-functions | 930 | (gnus-map-function mm-file-name-rewrite-functions |
| @@ -941,8 +940,9 @@ external if displayed external." | |||
| 941 | ;; `mailcap-mime-extensions'. | 940 | ;; `mailcap-mime-extensions'. |
| 942 | (setq suffix (car (rassoc (mm-handle-media-type handle) | 941 | (setq suffix (car (rassoc (mm-handle-media-type handle) |
| 943 | mailcap-mime-extensions)))) | 942 | mailcap-mime-extensions)))) |
| 944 | (setq file (make-temp-file (expand-file-name "mm." dir) | 943 | (setq file (with-file-modes #o600 |
| 945 | nil suffix)))) | 944 | (make-temp-file (expand-file-name "mm." dir) |
| 945 | nil suffix))))) | ||
| 946 | (let ((coding-system-for-write mm-binary-coding-system)) | 946 | (let ((coding-system-for-write mm-binary-coding-system)) |
| 947 | (write-region (point-min) (point-max) file nil 'nomesg)) | 947 | (write-region (point-min) (point-max) file nil 'nomesg)) |
| 948 | ;; The file is deleted after the viewer exists. If the users edits | 948 | ;; The file is deleted after the viewer exists. If the users edits |
diff --git a/lisp/image-dired.el b/lisp/image-dired.el index 768e941490d..1cc38ba714b 100644 --- a/lisp/image-dired.el +++ b/lisp/image-dired.el | |||
| @@ -771,8 +771,8 @@ Increase at own risk.") | |||
| 771 | process) | 771 | process) |
| 772 | (when (not (file-exists-p thumbnail-dir)) | 772 | (when (not (file-exists-p thumbnail-dir)) |
| 773 | (message "Creating thumbnail directory") | 773 | (message "Creating thumbnail directory") |
| 774 | (make-directory thumbnail-dir t) | 774 | (with-file-modes #o700 |
| 775 | (set-file-modes thumbnail-dir #o700)) | 775 | (make-directory thumbnail-dir t))) |
| 776 | 776 | ||
| 777 | ;; Thumbnail file creation processes begin here and are marshaled | 777 | ;; Thumbnail file creation processes begin here and are marshaled |
| 778 | ;; in a queue by `image-dired-create-thumb'. | 778 | ;; in a queue by `image-dired-create-thumb'. |