changeset 106604:a1ae5e2d1200

Make `dired-diff' more safe. (Bug#5225) * dired-aux.el (dired-diff): Signal an error when `file' equals to `current' or when `file' is a directory of the `current' file.
author Juri Linkov <juri@jurta.org>
date Thu, 17 Dec 2009 01:16:15 +0000
parents 90cf0c548f89
children b38517de715f
files lisp/ChangeLog lisp/dired-aux.el
diffstat 2 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Thu Dec 17 00:23:24 2009 +0000
+++ b/lisp/ChangeLog	Thu Dec 17 01:16:15 2009 +0000
@@ -1,3 +1,10 @@
+2009-12-17  Juri Linkov  <juri@jurta.org>
+
+	Make `dired-diff' more safe.  (Bug#5225)
+
+	* dired-aux.el (dired-diff): Signal an error when `file' equals to
+	`current' or when `file' is a directory of the `current' file.
+
 2009-12-17  Andreas Schwab  <schwab@linux-m68k.org>
 
 	* emacs-lisp/autoload.el (batch-update-autoloads): Only exclude
--- a/lisp/dired-aux.el	Thu Dec 17 00:23:24 2009 +0000
+++ b/lisp/dired-aux.el	Thu Dec 17 01:16:15 2009 +0000
@@ -90,7 +90,14 @@
 		       (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)