Sender: [EMAIL PROTECTED]
Newsgroups: comp.os.linux.development.system
Subject: Re: strange "mv" bug
References: <[EMAIL PROTECTED]>
From: [EMAIL PROTECTED] (Daniel R. Grayson)
Date: 18 Jul 2000 19:48:57 -0500
Message-ID: <[EMAIL PROTECTED]>
Lines: 24
X-Newsreader: Gnus v5.7/Emacs 20.6
--text follows this line--

It turns out to be a memory allocation bug.  Sometimes "mv" has to copy the
files, instead of moving them, for example, when moving from one filesystem
to another.  So keeps track of the inode numbers of the files it's already
moved, so in case it is about to move another link to a file it's already
moved, it can simply make a new link on the new file system.  Unfortunately,
when it saves the destination name of that earlier file, it forgets to create
a new copy of the string, so the memory for that string gets freed, the next
string gets the same memory, and over-writes it.

Here is a fix.

rhenium# diff -u fileutils-4.0/src/cp-hash.c-orig fileutils-4.0/src/cp-hash.c
--- fileutils-4.0/src/cp-hash.c-orig    Tue Jul 18 19:40:37 2000
+++ fileutils-4.0/src/cp-hash.c Tue Jul 18 19:40:42 2000
@@ -156,7 +156,7 @@
   ep = *hp = &ht->entry_tab[ht->first_free_entry++];
   ep->ino = ino;
   ep->dev = dev;
-  ep->node = (char *) node;
+  ep->node = (char *) strdup(node);
   ep->coll_link = ep2;         /* ep2 is NULL if not collision.  */
 
   return NULL;

-----------------------------------------------------------------------------

From: [EMAIL PROTECTED]
Subject: strange "mv" bug
Date: Tue, 18 Jul 2000 14:42:14 GMT
Path: 
vixen.cso.uiuc.edu!howland.erols.net!netnews.com!feeder.qis.net!sn-xit-01!supernews.com!sn-inject-01!news.supernews.com!not-for-mail
Newsgroups: comp.os.linux.development.system
Lines: 48
Sender: Phil Howard <[EMAIL PROTECTED]>
Message-ID: <[EMAIL PROTECTED]>
X-Complaints-To: [EMAIL PROTECTED]
User-Agent: tin/pre-1.4-19990216 ("Styrofoam") (UNIX) (Linux/2.2.10 (i686))
Xref: vixen.cso.uiuc.edu comp.os.linux.development.system:117376

It appears in Linux (Slackware 7.0 with 2.2.16 in this case, but also
in Redhat 6.0 with 2.2.10):

phil@procyon:/home/phil 2> ls -ld d f1 f2
ls: d: No such file or directory
ls: f1: No such file or directory
ls: f2: No such file or directory
phil@procyon:/home/phil 3> mkdir d
phil@procyon:/home/phil 4> touch f1
phil@procyon:/home/phil 5> ln f1 f2
phil@procyon:/home/phil 6> mv f1 f2 d
mv: d/f2: No such file or directory
phil@procyon:/home/phil 7> mv f2 d

But in Solaris 2.7 it works as expected:

phil@sirius:/home/phil 2> ls -ld d f1 f2
d: No such file or directory
f1: No such file or directory
f2: No such file or directory
phil@sirius:/home/phil 3> mkdir d
phil@sirius:/home/phil 4> touch f1
phil@sirius:/home/phil 5> ln f1 f2
phil@sirius:/home/phil 6> mv f1 f2 d
phil@sirius:/home/phil 7> 

Any ideas why a single invokation of "mv" cannot move to links to the same
object from them both being in a common directory to a different common
directory?  Oh, and it doesn't matter that the directories are parent
and child:

phil@procyon:/home/phil 8> ls -ld e
ls: e: No such file or directory
phil@procyon:/home/phil 9> mkdir e
phil@procyon:/home/phil 10> mv d/f1 d/f2 e
mv: e/f2: No such file or directory
phil@procyon:/home/phil 11> mv d/f2 e
phil@procyon:/home/phil 12> 

I'll have to write some code to see if I can make the problem happen
with the rename() system call to see if it's a bug in the kernel.
I suspect a problem with the "mv" command, but I cannot imagine what
that could be.

-- 
| Phil Howard - KA9WGN | My current websites: linuxhomepage.com, ham.org
| phil  (at)  ipal.net +----------------------------------------------------
| Dallas - Texas - USA | [EMAIL PROTECTED]

Reply via email to