bug fix for smbclient/tar
Glenn Burkhardt
glenn at aoi.ultranet.com
Sat Dec 16 16:02:08 GMT 2000
There's a race condition: when a file increases in size when being archived by
the tar function in smbclient, the resulting tar file is created with an
invalid format. The tar header for the file has the wrong length, and many tar
programs will abort when they get to the invalid header/file.
I've seen this happen when using smbclient/tar to back up a Win98 computer, and
there's incoming email. The mailbox changes size while the network backup is
running, and the resulting backup file is (mostly) unusable.
A simple fix is to not read more of the file than was there during the file
size query. Then only one file in the tar archive will be bad.
The attached patch is for the 2.0.7 version, source/client/clitar.c
-------------- next part --------------
--- clitar.c.orig Sat Dec 16 09:50:59 2000
+++ clitar.c Sat Dec 16 10:46:51 2000
@@ -729,6 +729,17 @@
break;
}
+ nread += datalen;
+
+ /* if file size has increased since we made file size query, truncate
+ read so tar header for this file will be correct.
+ */
+ if (nread > finfo.size) {
+ datalen -= nread - finfo.size;
+ DEBUG(0,("File size change - truncating %s to %d bytes\n",
+ finfo.name, (int)finfo.size));
+ }
+
/* add received bits of file to buffer - dotarbuf will
* write out in 512 byte intervals */
if (dotarbuf(tarhandle,data,datalen) != datalen) {
@@ -736,7 +747,6 @@
break;
}
- nread += datalen;
if (datalen == 0) {
DEBUG(0,("Error reading file %s. Got 0 bytes\n", rname));
break;
More information about the samba
mailing list