GNU bug report logs - #10489
24.0.92; dired-do-copy may create infinite directory hierarchy

Previous Next

Package: emacs;

Reported by: michael_heerdegen <at> web.de

Date: Thu, 12 Jan 2012 19:36:01 UTC

Severity: important

Tags: patch

Merged with 11130

Found in version 24.0.92

Done: Chong Yidong <cyd <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Eli Zaretskii <eliz <at> gnu.org>
To: Thierry Volpiatto <thierry.volpiatto <at> gmail.com>
Cc: 10489 <at> debbugs.gnu.org
Subject: bug#10489: 24.0.92; dired-do-copy may create infinite directory hierarchy
Date: Fri, 13 Jan 2012 09:23:57 +0200
> From: Thierry Volpiatto <thierry.volpiatto <at> gmail.com>
> Date: Thu, 12 Jan 2012 22:33:38 +0100
> 
> Hi, here a patch that should fix this.

Thanks.

> +  (when (string= (file-name-as-directory from)
> +                 (file-name-as-directory to))
> +    (error "Can't copy to same directory"))
>    (let ((attrs (file-attributes from)))
>      (if (and recursive
>  	     (eq t (car attrs))
> @@ -1431,7 +1434,10 @@
>                           (marker-char (dired-file-marker from)) ; slow
>                           (t nil))))
>  	    (when (and (file-directory-p from)
> -		       (file-directory-p to)
> +		       (or (file-directory-p to)
> +                           (string= (file-name-as-directory from)
> +                                    (file-name-as-directory
> +                                     (file-name-directory to))))
>  		       (eq file-creator 'dired-copy-file))
>  	      (setq to (file-name-directory to)))
>              (condition-case err
> diff --git a/lisp/files.el b/lisp/files.el
> --- a/lisp/files.el
> +++ b/lisp/files.el
> @@ -4928,6 +4928,9 @@
>  	    (format "Copy directory %s to: " dir)
>  	    default-directory default-directory nil nil)
>  	   current-prefix-arg t nil)))
> +  (when (string= (file-name-as-directory directory)
> +                 (file-name-as-directory newname))
> +    (error "Can't copy to same directory"))
>    ;; If default-directory is a remote directory, make sure we find its
>    ;; copy-directory handler.
>    (let ((handler (or (find-file-name-handler directory 'copy-directory)

I don't think this will solves all the use cases.  File names are not
strings, you cannot compare them as literal strings and hope to plumb
all the leaks.

Some situations which I think this patch will not handle correctly:

 . file names with different letter-case on a case-insensitive file
   system

 . relative vs absolute file names

 . file names that are hard links to the same directory (this includes
   the infamous 8+3 short aliases on Windows)

I didn't actually try the patch, so apologies if I missed something
which makes these non-issues.

Thanks again for working on this.




This bug report was last modified 13 years and 58 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.