Be sure to read from the given path, not the one used in the header.
This commit is contained in:
@@ -936,7 +936,8 @@ static int putOctal (char *cp, int len, long value)
|
|||||||
|
|
||||||
/* Write out a tar header for the specified file/directory/whatever */
|
/* Write out a tar header for the specified file/directory/whatever */
|
||||||
static int
|
static int
|
||||||
writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *statbuf)
|
writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name,
|
||||||
|
const char *real_name, struct stat *statbuf)
|
||||||
{
|
{
|
||||||
long chksum=0;
|
long chksum=0;
|
||||||
struct TarHeader header;
|
struct TarHeader header;
|
||||||
@@ -945,7 +946,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
|
|||||||
|
|
||||||
memset( &header, 0, size);
|
memset( &header, 0, size);
|
||||||
|
|
||||||
strncpy(header.name, fileName, sizeof(header.name));
|
strncpy(header.name, header_name, sizeof(header.name));
|
||||||
|
|
||||||
putOctal(header.mode, sizeof(header.mode), statbuf->st_mode);
|
putOctal(header.mode, sizeof(header.mode), statbuf->st_mode);
|
||||||
putOctal(header.uid, sizeof(header.uid), statbuf->st_uid);
|
putOctal(header.uid, sizeof(header.uid), statbuf->st_uid);
|
||||||
@@ -971,7 +972,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
|
|||||||
int link_size=0;
|
int link_size=0;
|
||||||
char buffer[BUFSIZ];
|
char buffer[BUFSIZ];
|
||||||
header.typeflag = SYMTYPE;
|
header.typeflag = SYMTYPE;
|
||||||
link_size = readlink(fileName, buffer, sizeof(buffer) - 1);
|
link_size = readlink(real_name, buffer, sizeof(buffer) - 1);
|
||||||
if ( link_size < 0) {
|
if ( link_size < 0) {
|
||||||
perror_msg("Error reading symlink '%s'", header.name);
|
perror_msg("Error reading symlink '%s'", header.name);
|
||||||
return ( FALSE);
|
return ( FALSE);
|
||||||
@@ -995,7 +996,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
|
|||||||
header.typeflag = REGTYPE;
|
header.typeflag = REGTYPE;
|
||||||
putOctal(header.size, sizeof(header.size), statbuf->st_size);
|
putOctal(header.size, sizeof(header.size), statbuf->st_size);
|
||||||
} else {
|
} else {
|
||||||
error_msg("%s: Unknown file type\n", fileName);
|
error_msg("%s: Unknown file type\n", real_name);
|
||||||
return ( FALSE);
|
return ( FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1012,7 +1013,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
|
|||||||
|
|
||||||
/* Now write the header out to disk */
|
/* Now write the header out to disk */
|
||||||
if ((size=full_write(tbInfo->tarFd, (char*)&header, sizeof(struct TarHeader))) < 0) {
|
if ((size=full_write(tbInfo->tarFd, (char*)&header, sizeof(struct TarHeader))) < 0) {
|
||||||
error_msg(io_error, fileName, strerror(errno));
|
error_msg(io_error, real_name, strerror(errno));
|
||||||
return ( FALSE);
|
return ( FALSE);
|
||||||
}
|
}
|
||||||
/* Pad the header up to the tar block size */
|
/* Pad the header up to the tar block size */
|
||||||
@@ -1034,6 +1035,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
|
|||||||
static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* userData)
|
static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* userData)
|
||||||
{
|
{
|
||||||
struct TarBallInfo *tbInfo = (struct TarBallInfo *)userData;
|
struct TarBallInfo *tbInfo = (struct TarBallInfo *)userData;
|
||||||
|
const char *header_name;
|
||||||
#if defined BB_FEATURE_TAR_EXCLUDE
|
#if defined BB_FEATURE_TAR_EXCLUDE
|
||||||
char** tmpList;
|
char** tmpList;
|
||||||
#endif
|
#endif
|
||||||
@@ -1069,13 +1071,14 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void*
|
|||||||
return( TRUE);
|
return( TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fileName[0] == '/') {
|
header_name = fileName;
|
||||||
|
while (header_name[0] == '/') {
|
||||||
static int alreadyWarned=FALSE;
|
static int alreadyWarned=FALSE;
|
||||||
if (alreadyWarned==FALSE) {
|
if (alreadyWarned==FALSE) {
|
||||||
error_msg("Removing leading '/' from member names\n");
|
error_msg("Removing leading '/' from member names\n");
|
||||||
alreadyWarned=TRUE;
|
alreadyWarned=TRUE;
|
||||||
}
|
}
|
||||||
fileName++;
|
header_name++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(fileName) >= NAME_SIZE) {
|
if (strlen(fileName) >= NAME_SIZE) {
|
||||||
@@ -1083,7 +1086,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void*
|
|||||||
return ( TRUE);
|
return ( TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileName[0] == '\0')
|
if (header_name[0] == '\0')
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
#if defined BB_FEATURE_TAR_EXCLUDE
|
#if defined BB_FEATURE_TAR_EXCLUDE
|
||||||
@@ -1091,7 +1094,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void*
|
|||||||
for (tmpList=tbInfo->excludeList; tmpList && *tmpList; tmpList++) {
|
for (tmpList=tbInfo->excludeList; tmpList && *tmpList; tmpList++) {
|
||||||
/* Do some extra hoop jumping for when directory names
|
/* Do some extra hoop jumping for when directory names
|
||||||
* end in '/' but the entry in tmpList doesn't */
|
* end in '/' but the entry in tmpList doesn't */
|
||||||
if (strncmp( *tmpList, fileName, strlen(*tmpList))==0 || (
|
if (strncmp( *tmpList, header_name, strlen(*tmpList))==0 || (
|
||||||
fileName[strlen(fileName)-1]=='/'
|
fileName[strlen(fileName)-1]=='/'
|
||||||
&& strncmp( *tmpList, fileName,
|
&& strncmp( *tmpList, fileName,
|
||||||
MIN(strlen(fileName)-1, strlen(*tmpList)))==0)) {
|
MIN(strlen(fileName)-1, strlen(*tmpList)))==0)) {
|
||||||
@@ -1100,7 +1103,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void*
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (writeTarHeader(tbInfo, fileName, statbuf)==FALSE) {
|
if (writeTarHeader(tbInfo, header_name, fileName, statbuf)==FALSE) {
|
||||||
return( FALSE);
|
return( FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
tar.c
23
tar.c
@@ -936,7 +936,8 @@ static int putOctal (char *cp, int len, long value)
|
|||||||
|
|
||||||
/* Write out a tar header for the specified file/directory/whatever */
|
/* Write out a tar header for the specified file/directory/whatever */
|
||||||
static int
|
static int
|
||||||
writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *statbuf)
|
writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name,
|
||||||
|
const char *real_name, struct stat *statbuf)
|
||||||
{
|
{
|
||||||
long chksum=0;
|
long chksum=0;
|
||||||
struct TarHeader header;
|
struct TarHeader header;
|
||||||
@@ -945,7 +946,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
|
|||||||
|
|
||||||
memset( &header, 0, size);
|
memset( &header, 0, size);
|
||||||
|
|
||||||
strncpy(header.name, fileName, sizeof(header.name));
|
strncpy(header.name, header_name, sizeof(header.name));
|
||||||
|
|
||||||
putOctal(header.mode, sizeof(header.mode), statbuf->st_mode);
|
putOctal(header.mode, sizeof(header.mode), statbuf->st_mode);
|
||||||
putOctal(header.uid, sizeof(header.uid), statbuf->st_uid);
|
putOctal(header.uid, sizeof(header.uid), statbuf->st_uid);
|
||||||
@@ -971,7 +972,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
|
|||||||
int link_size=0;
|
int link_size=0;
|
||||||
char buffer[BUFSIZ];
|
char buffer[BUFSIZ];
|
||||||
header.typeflag = SYMTYPE;
|
header.typeflag = SYMTYPE;
|
||||||
link_size = readlink(fileName, buffer, sizeof(buffer) - 1);
|
link_size = readlink(real_name, buffer, sizeof(buffer) - 1);
|
||||||
if ( link_size < 0) {
|
if ( link_size < 0) {
|
||||||
perror_msg("Error reading symlink '%s'", header.name);
|
perror_msg("Error reading symlink '%s'", header.name);
|
||||||
return ( FALSE);
|
return ( FALSE);
|
||||||
@@ -995,7 +996,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
|
|||||||
header.typeflag = REGTYPE;
|
header.typeflag = REGTYPE;
|
||||||
putOctal(header.size, sizeof(header.size), statbuf->st_size);
|
putOctal(header.size, sizeof(header.size), statbuf->st_size);
|
||||||
} else {
|
} else {
|
||||||
error_msg("%s: Unknown file type\n", fileName);
|
error_msg("%s: Unknown file type\n", real_name);
|
||||||
return ( FALSE);
|
return ( FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1012,7 +1013,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
|
|||||||
|
|
||||||
/* Now write the header out to disk */
|
/* Now write the header out to disk */
|
||||||
if ((size=full_write(tbInfo->tarFd, (char*)&header, sizeof(struct TarHeader))) < 0) {
|
if ((size=full_write(tbInfo->tarFd, (char*)&header, sizeof(struct TarHeader))) < 0) {
|
||||||
error_msg(io_error, fileName, strerror(errno));
|
error_msg(io_error, real_name, strerror(errno));
|
||||||
return ( FALSE);
|
return ( FALSE);
|
||||||
}
|
}
|
||||||
/* Pad the header up to the tar block size */
|
/* Pad the header up to the tar block size */
|
||||||
@@ -1034,6 +1035,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
|
|||||||
static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* userData)
|
static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* userData)
|
||||||
{
|
{
|
||||||
struct TarBallInfo *tbInfo = (struct TarBallInfo *)userData;
|
struct TarBallInfo *tbInfo = (struct TarBallInfo *)userData;
|
||||||
|
const char *header_name;
|
||||||
#if defined BB_FEATURE_TAR_EXCLUDE
|
#if defined BB_FEATURE_TAR_EXCLUDE
|
||||||
char** tmpList;
|
char** tmpList;
|
||||||
#endif
|
#endif
|
||||||
@@ -1069,13 +1071,14 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void*
|
|||||||
return( TRUE);
|
return( TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fileName[0] == '/') {
|
header_name = fileName;
|
||||||
|
while (header_name[0] == '/') {
|
||||||
static int alreadyWarned=FALSE;
|
static int alreadyWarned=FALSE;
|
||||||
if (alreadyWarned==FALSE) {
|
if (alreadyWarned==FALSE) {
|
||||||
error_msg("Removing leading '/' from member names\n");
|
error_msg("Removing leading '/' from member names\n");
|
||||||
alreadyWarned=TRUE;
|
alreadyWarned=TRUE;
|
||||||
}
|
}
|
||||||
fileName++;
|
header_name++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(fileName) >= NAME_SIZE) {
|
if (strlen(fileName) >= NAME_SIZE) {
|
||||||
@@ -1083,7 +1086,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void*
|
|||||||
return ( TRUE);
|
return ( TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileName[0] == '\0')
|
if (header_name[0] == '\0')
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
#if defined BB_FEATURE_TAR_EXCLUDE
|
#if defined BB_FEATURE_TAR_EXCLUDE
|
||||||
@@ -1091,7 +1094,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void*
|
|||||||
for (tmpList=tbInfo->excludeList; tmpList && *tmpList; tmpList++) {
|
for (tmpList=tbInfo->excludeList; tmpList && *tmpList; tmpList++) {
|
||||||
/* Do some extra hoop jumping for when directory names
|
/* Do some extra hoop jumping for when directory names
|
||||||
* end in '/' but the entry in tmpList doesn't */
|
* end in '/' but the entry in tmpList doesn't */
|
||||||
if (strncmp( *tmpList, fileName, strlen(*tmpList))==0 || (
|
if (strncmp( *tmpList, header_name, strlen(*tmpList))==0 || (
|
||||||
fileName[strlen(fileName)-1]=='/'
|
fileName[strlen(fileName)-1]=='/'
|
||||||
&& strncmp( *tmpList, fileName,
|
&& strncmp( *tmpList, fileName,
|
||||||
MIN(strlen(fileName)-1, strlen(*tmpList)))==0)) {
|
MIN(strlen(fileName)-1, strlen(*tmpList)))==0)) {
|
||||||
@@ -1100,7 +1103,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void*
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (writeTarHeader(tbInfo, fileName, statbuf)==FALSE) {
|
if (writeTarHeader(tbInfo, header_name, fileName, statbuf)==FALSE) {
|
||||||
return( FALSE);
|
return( FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user