[BusyBox] bug#1287: busybox 'mv' incorrectly deletes target files on failure

Matthias Lang matthias at corelatus.se
Mon Nov 18 08:46:03 UTC 2002


Package: busybox
Version: 0.60.5
Severity: normal

Busybox 'mv' does the wrong thing after a failed attempt to move files
across filesystems. It deletes the target file, even in cases where
'mv' fails because the source file does not exist.

This affects busybox 0.60.4. Looking at CVS, it hasn't been fixed, so
it's also a problem in 0.60.5 and in the development code.

Example:

  matthias >ls -l /usr/local/demo/a
  -rw-rw-r--    1 matthias matthias     2035 Nov 18 15:58 /usr/local/demo/a
  matthias >./busybox mv nosuchfile /usr/local/demo/a
  mv: nosuchfile: No such file or directory
  matthias >ls -l /usr/local/demo/a
  ls: /usr/local/demo/a: No such file or directory

This only happens if the source and target are on different
filesystems (on my machine, /usr/local is not the same filesystem as
/home).

The problem is in manual_rename(). One fix would be to guard the
unlink() call:

 if (source_exists && unlink(dest) < 0) {
                        perror_msg("cannot remove `%s'", dest);
                        return -1;
 }

But I don't understand why manual_rename() doesn't just call it quits
when it realises the source file doesn't exist, i.e. just do:

 if (stat(source, &source_stat) < 0) {
            perror_msg("unable to stat `%s'", source);
            return -1;
 }

Matthias



More information about the busybox mailing list