From unknown Sat Jun 14 19:24:11 2025 X-Loop: owner@emacsbugs.donarmstrong.com Subject: bug#5225: dired-diff should be more safe Reply-To: Juri Linkov , 5225@debbugs.gnu.org Resent-From: Juri Linkov Resent-To: bug-submit-list@lists.donarmstrong.com Resent-CC: Emacs Bugs 2Resent-Date: Wed, 16 Dec 2009 09:40:06 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-Emacs-PR-Message: report 5225 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Received: via spool by submit@emacsbugs.donarmstrong.com id=B.12609560336137 (code B ref -1); Wed, 16 Dec 2009 09:40:06 +0000 Received: (at submit) by emacsbugs.donarmstrong.com; 16 Dec 2009 09:33:53 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.5-bugs.debian.org_2005_01_02 (2008-06-10) on rzlab.ucr.edu X-Spam-Level: X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. X-Spam-Status: No, score=-1.2 required=4.0 tests=AWL,MURPHY_DRUGS_REL8 autolearn=ham version=3.2.5-bugs.debian.org_2005_01_02 Received: from fencepost.gnu.org (fencepost.gnu.org [140.186.70.10]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id nBG9Xpax006134 for ; Wed, 16 Dec 2009 01:33:52 -0800 Received: from mx10.gnu.org ([199.232.76.166]:46709) by fencepost.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NKqGU-0002y7-MR for emacs-pretest-bug@gnu.org; Wed, 16 Dec 2009 04:33:50 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NKqGR-0001Af-UT for emacs-pretest-bug@gnu.org; Wed, 16 Dec 2009 04:33:50 -0500 Received: from smtp-out3.starman.ee ([85.253.0.5]:45080 helo=mx1.starman.ee) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NKqGR-0001AZ-IU for emacs-pretest-bug@gnu.org; Wed, 16 Dec 2009 04:33:47 -0500 X-Virus-Scanned: by Amavisd-New at mx1.starman.ee Received: from mail.starman.ee (82.131.94.242.cable.starman.ee [82.131.94.242]) by mx1.starman.ee (Postfix) with ESMTP id D06C23F41E9 for ; Wed, 16 Dec 2009 11:33:41 +0200 (EET) From: Juri Linkov To: emacs-pretest-bug@gnu.org Organization: JURTA Date: Wed, 16 Dec 2009 11:19:09 +0200 Message-ID: <87vdg7cm42.fsf@mail.jurta.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.90 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Currently using `dired-diff' has a high risk of deleting a file. When two compared file names refer to the same file, or when one of them is the directory name of the second file (thus the file is compared against itself), then the user may not notice that `diff' compares the same file with itself, and when `diff' says there are no differences, decide to delete the file (thinking that two files have the same content). The patch below eliminates this risk by signalling an error when comparing the same file to itself: === modified file 'lisp/dired-aux.el' --- lisp/dired-aux.el 2009-11-25 17:15:19 +0000 +++ lisp/dired-aux.el 2009-12-16 09:16:34 +0000 @@ -60,27 +60,44 @@ (if (stringp diff-switches) diff-switches (mapconcat 'identity diff-switches " "))))))) - (diff file (dired-get-filename t) switches)) + (let ((current (dired-get-filename t))) + (when (or (equal (expand-file-name file) + (expand-file-name current)) + (and (file-directory-p file) + (equal (expand-file-name current file) + (expand-file-name current)))) + (error "Attempt to compare the file to itself")) + (diff file current switches))) ;;;###autoload (defun dired-backup-diff (&optional switches) -- Juri Linkov http://www.jurta.org/emacs/ From unknown Sat Jun 14 19:24:11 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.427 (Entity 5.427) X-Loop: bug-gnu-emacs@gnu.org From: bug-gnu-emacs@gnu.org (Emacs bug Tracking System) To: Juri Linkov Subject: bug#5225 closed by Juri Linkov (Re: bug#5225: dired-diff should be more safe) Message-ID: References: <87eimubdnm.fsf@mail.jurta.org> <87vdg7cm42.fsf@mail.jurta.org> X-Emacs-PR-Message: they-closed 5225 X-Emacs-PR-Package: emacs Reply-To: 5225@debbugs.gnu.org Date: Fri, 18 Dec 2009 07:33:03 +0000 Content-Type: multipart/mixed; boundary="----------=_1261121583-10805-1" This is a multi-part message in MIME format... ------------=_1261121583-10805-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This is an automatic notification regarding your bug report which was filed against the emacs package: #5225: dired-diff should be more safe It has been closed by Juri Linkov . Their explanation is attached below along with your original report. If this explanation is unsatisfactory and you have not received a better one in a separate message then please contact Juri Linkov by replying to this email. --=20 5225: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D5225 Emacs Bug Tracking System Contact bug-gnu-emacs@gnu.org with problems ------------=_1261121583-10805-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 5225-done) by debbugs.gnu.org; 18 Dec 2009 07:32:29 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NLXK8-0002nV-UT for submit@debbugs.gnu.org; Fri, 18 Dec 2009 02:32:28 -0500 Received: from smtp-out3.starman.ee ([85.253.0.5] helo=mx1.starman.ee) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NLWL4-0002Gz-84 for 5225-done@emacsbugs.donarmstrong.com; Fri, 18 Dec 2009 01:29:22 -0500 X-Virus-Scanned: by Amavisd-New at mx1.starman.ee Received: from mail.starman.ee (82.131.31.103.cable.starman.ee [82.131.31.103]) by mx1.starman.ee (Postfix) with ESMTP id 731383F410E for <5225-done@emacsbugs.donarmstrong.com>; Thu, 17 Dec 2009 04:07:27 +0200 (EET) From: Juri Linkov To: 5225-done@debbugs.gnu.org Subject: Re: bug#5225: dired-diff should be more safe Organization: JURTA References: <87vdg7cm42.fsf@mail.jurta.org> Date: Thu, 17 Dec 2009 03:19:27 +0200 In-Reply-To: <87vdg7cm42.fsf@mail.jurta.org> (Juri Linkov's message of "Wed, 16 Dec 2009 11:19:09 +0200") Message-ID: <87eimubdnm.fsf@mail.jurta.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.90 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Debbugs-Envelope-To: 5225-done X-Mailman-Approved-At: Fri, 18 Dec 2009 02:32:26 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org Fixed. -- Juri Linkov http://www.jurta.org/emacs/ ------------=_1261121583-10805-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by emacsbugs.donarmstrong.com; 16 Dec 2009 09:33:53 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.5-bugs.debian.org_2005_01_02 (2008-06-10) on rzlab.ucr.edu X-Spam-Level: X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. X-Spam-Status: No, score=-1.2 required=4.0 tests=AWL,MURPHY_DRUGS_REL8 autolearn=ham version=3.2.5-bugs.debian.org_2005_01_02 Received: from fencepost.gnu.org (fencepost.gnu.org [140.186.70.10]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id nBG9Xpax006134 for ; Wed, 16 Dec 2009 01:33:52 -0800 Received: from mx10.gnu.org ([199.232.76.166]:46709) by fencepost.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NKqGU-0002y7-MR for emacs-pretest-bug@gnu.org; Wed, 16 Dec 2009 04:33:50 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NKqGR-0001Af-UT for emacs-pretest-bug@gnu.org; Wed, 16 Dec 2009 04:33:50 -0500 Received: from smtp-out3.starman.ee ([85.253.0.5]:45080 helo=mx1.starman.ee) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NKqGR-0001AZ-IU for emacs-pretest-bug@gnu.org; Wed, 16 Dec 2009 04:33:47 -0500 X-Virus-Scanned: by Amavisd-New at mx1.starman.ee Received: from mail.starman.ee (82.131.94.242.cable.starman.ee [82.131.94.242]) by mx1.starman.ee (Postfix) with ESMTP id D06C23F41E9 for ; Wed, 16 Dec 2009 11:33:41 +0200 (EET) From: Juri Linkov To: emacs-pretest-bug@gnu.org Subject: dired-diff should be more safe Organization: JURTA Date: Wed, 16 Dec 2009 11:19:09 +0200 Message-ID: <87vdg7cm42.fsf@mail.jurta.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.90 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Currently using `dired-diff' has a high risk of deleting a file. When two compared file names refer to the same file, or when one of them is the directory name of the second file (thus the file is compared against itself), then the user may not notice that `diff' compares the same file with itself, and when `diff' says there are no differences, decide to delete the file (thinking that two files have the same content). The patch below eliminates this risk by signalling an error when comparing the same file to itself: === modified file 'lisp/dired-aux.el' --- lisp/dired-aux.el 2009-11-25 17:15:19 +0000 +++ lisp/dired-aux.el 2009-12-16 09:16:34 +0000 @@ -60,27 +60,44 @@ (if (stringp diff-switches) diff-switches (mapconcat 'identity diff-switches " "))))))) - (diff file (dired-get-filename t) switches)) + (let ((current (dired-get-filename t))) + (when (or (equal (expand-file-name file) + (expand-file-name current)) + (and (file-directory-p file) + (equal (expand-file-name current file) + (expand-file-name current)))) + (error "Attempt to compare the file to itself")) + (diff file current switches))) ;;;###autoload (defun dired-backup-diff (&optional switches) -- Juri Linkov http://www.jurta.org/emacs/ ------------=_1261121583-10805-1--