From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#10403: epg--make-temp-file permissions race condition fixes Date: Thu, 29 Dec 2011 14:22:56 -0800 Organization: UCLA Computer Science Department Message-ID: <4EFCE840.4000405@cs.ucla.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1325197399 8382 80.91.229.12 (29 Dec 2011 22:23:19 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 29 Dec 2011 22:23:19 +0000 (UTC) To: 10403@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Dec 29 23:23:15 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RgONX-0001M0-F6 for geb-bug-gnu-emacs@m.gmane.org; Thu, 29 Dec 2011 23:23:15 +0100 Original-Received: from localhost ([::1]:58249 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RgONW-0005x6-KN for geb-bug-gnu-emacs@m.gmane.org; Thu, 29 Dec 2011 17:23:14 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:44296) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RgONT-0005wo-L4 for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2011 17:23:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RgONS-00048z-QO for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2011 17:23:11 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:58069) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RgONS-00048p-Oj for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2011 17:23:10 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1RgOQE-0006O8-FD for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2011 17:26:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 29 Dec 2011 22:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 10403 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.132519755724544 (code B ref -1); Thu, 29 Dec 2011 22:26:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 29 Dec 2011 22:25:57 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RgOQ8-0006No-U8 for submit@debbugs.gnu.org; Thu, 29 Dec 2011 17:25:57 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RgOQ5-0006Nd-Mj for submit@debbugs.gnu.org; Thu, 29 Dec 2011 17:25:55 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RgONI-00047z-Jq for submit@debbugs.gnu.org; Thu, 29 Dec 2011 17:23:01 -0500 Original-Received: from lists.gnu.org ([140.186.70.17]:44451) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RgONI-00047v-IU for submit@debbugs.gnu.org; Thu, 29 Dec 2011 17:23:00 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:44252) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RgONH-0005wb-Jg for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2011 17:23:00 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RgONG-00047c-FI for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2011 17:22:59 -0500 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:38592) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RgONG-00047P-3j for bug-gnu-emacs@gnu.org; Thu, 29 Dec 2011 17:22:58 -0500 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id A2A6739E8006 for ; Thu, 29 Dec 2011 14:22:56 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vXDN3sZDTnwk for ; Thu, 29 Dec 2011 14:22:55 -0800 (PST) Original-Received: from [192.168.1.10] (pool-71-189-109-235.lsanca.fios.verizon.net [71.189.109.235]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 2450DA60001 for ; Thu, 29 Dec 2011 14:22:55 -0800 (PST) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111124 Thunderbird/8.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Thu, 29 Dec 2011 17:26:02 -0500 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:55283 Archived-At: Tags: patch === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2011-12-29 21:55:33 +0000 +++ lisp/ChangeLog 2011-12-29 22:08:29 +0000 @@ -1,5 +1,8 @@ 2011-12-29 Paul Eggert + * epg.el (epg--make-temp-file): Avoid permission race conditions + when creating temporary directories and files on older Emacs. + * files.el (move-file-to-trash): Preserve default file modes on error. (Bug#10401) === modified file 'lisp/epg.el' --- lisp/epg.el 2011-11-23 07:03:56 +0000 +++ lisp/epg.el 2011-12-29 22:08:29 +0000 @@ -1951,14 +1951,16 @@ 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 @@ (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)