tar garbles symlinks
David Vrabel
dvrabel at arcom.co.uk
Tue Aug 15 08:44:34 UTC 2000
Package: busybox
Version: 0.45
Severity: Normal
When creating a tar archive containing directories containing multiple
symlinks the symlinks become garbled
eg
adduser -> /bin/tinylogin
ls -> /bin/busybox
becomes (when untarred)
adduser -> /bin/tinylogin
ls -> /bin/busboxin
(note reproducing this behavior seems to require many symlinks in a
directory)
The problem lies in writeTarHeader(). readlink() fills a character
buffer with the link name. This buffer is not null terminated =>
header.linkname is not filled correctly.
Suggested fix:
--- tar.c.old Wed Jun 21 16:19:33 2000
+++ tar.c Tue Aug 15 09:22:53 2000
@@ -824,13 +824,15 @@
/* WARNING/NOTICE: I break Hard Links */
if (S_ISLNK(statbuf->st_mode)) {
- char buffer[BUFSIZ];
+ char buffer[sizeof(header.linkname)];
+ int len;
header.typeflag = SYMTYPE;
- if ( readlink(fileName, buffer, sizeof(buffer) - 1) < 0)
{
+ if ( (len=readlink(fileName, buffer, sizeof(buffer) -
1)) < 0) { errorMsg("Error reading symlink '%s':
%s\n", header.name, strerror(errno));
return ( FALSE);
}
- strncpy(header.linkname, buffer,
sizeof(header.linkname));
+ strncpy(header.linkname, buffer,
sizeof(header.linkname));
+ header.linkname[len]='\0';
} else if (S_ISDIR(statbuf->st_mode)) {
header.typeflag = DIRTYPE;
strncat(header.name, "/",
sizeof(header.name));
---------------------------------------
Received: (at 1024-done) by bugs.lineo.com; 21 Aug 2000 23:09:17 +0000
More information about the busybox
mailing list