diff options
author | Matt Kraai <kraai@debian.org> | 2000-12-19 20:45:49 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2000-12-19 20:45:49 +0000 |
commit | e80a2633bc4d8ef8d4370653fdefafe942927452 (patch) | |
tree | 45f1898943f51f58c8c9b852d9f824a0f387e0b4 | |
parent | 8eb5985f94a3f8a08c9e80274019175ea87c76b9 (diff) | |
download | busybox-w32-e80a2633bc4d8ef8d4370653fdefafe942927452.tar.gz busybox-w32-e80a2633bc4d8ef8d4370653fdefafe942927452.tar.bz2 busybox-w32-e80a2633bc4d8ef8d4370653fdefafe942927452.zip |
Be sure to read from the given path, not the one used in the header.
-rw-r--r-- | archival/tar.c | 23 | ||||
-rw-r--r-- | tar.c | 23 |
2 files changed, 26 insertions, 20 deletions
diff --git a/archival/tar.c b/archival/tar.c index 463cc50c7..04e351e37 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -936,7 +936,8 @@ static int putOctal (char *cp, int len, long value) | |||
936 | 936 | ||
937 | /* Write out a tar header for the specified file/directory/whatever */ | 937 | /* Write out a tar header for the specified file/directory/whatever */ |
938 | static int | 938 | static int |
939 | writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *statbuf) | 939 | writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name, |
940 | const char *real_name, struct stat *statbuf) | ||
940 | { | 941 | { |
941 | long chksum=0; | 942 | long chksum=0; |
942 | struct TarHeader header; | 943 | struct TarHeader header; |
@@ -945,7 +946,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st | |||
945 | 946 | ||
946 | memset( &header, 0, size); | 947 | memset( &header, 0, size); |
947 | 948 | ||
948 | strncpy(header.name, fileName, sizeof(header.name)); | 949 | strncpy(header.name, header_name, sizeof(header.name)); |
949 | 950 | ||
950 | putOctal(header.mode, sizeof(header.mode), statbuf->st_mode); | 951 | putOctal(header.mode, sizeof(header.mode), statbuf->st_mode); |
951 | putOctal(header.uid, sizeof(header.uid), statbuf->st_uid); | 952 | putOctal(header.uid, sizeof(header.uid), statbuf->st_uid); |
@@ -971,7 +972,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st | |||
971 | int link_size=0; | 972 | int link_size=0; |
972 | char buffer[BUFSIZ]; | 973 | char buffer[BUFSIZ]; |
973 | header.typeflag = SYMTYPE; | 974 | header.typeflag = SYMTYPE; |
974 | link_size = readlink(fileName, buffer, sizeof(buffer) - 1); | 975 | link_size = readlink(real_name, buffer, sizeof(buffer) - 1); |
975 | if ( link_size < 0) { | 976 | if ( link_size < 0) { |
976 | perror_msg("Error reading symlink '%s'", header.name); | 977 | perror_msg("Error reading symlink '%s'", header.name); |
977 | return ( FALSE); | 978 | return ( FALSE); |
@@ -995,7 +996,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st | |||
995 | header.typeflag = REGTYPE; | 996 | header.typeflag = REGTYPE; |
996 | putOctal(header.size, sizeof(header.size), statbuf->st_size); | 997 | putOctal(header.size, sizeof(header.size), statbuf->st_size); |
997 | } else { | 998 | } else { |
998 | error_msg("%s: Unknown file type\n", fileName); | 999 | error_msg("%s: Unknown file type\n", real_name); |
999 | return ( FALSE); | 1000 | return ( FALSE); |
1000 | } | 1001 | } |
1001 | 1002 | ||
@@ -1012,7 +1013,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st | |||
1012 | 1013 | ||
1013 | /* Now write the header out to disk */ | 1014 | /* Now write the header out to disk */ |
1014 | if ((size=full_write(tbInfo->tarFd, (char*)&header, sizeof(struct TarHeader))) < 0) { | 1015 | if ((size=full_write(tbInfo->tarFd, (char*)&header, sizeof(struct TarHeader))) < 0) { |
1015 | error_msg(io_error, fileName, strerror(errno)); | 1016 | error_msg(io_error, real_name, strerror(errno)); |
1016 | return ( FALSE); | 1017 | return ( FALSE); |
1017 | } | 1018 | } |
1018 | /* Pad the header up to the tar block size */ | 1019 | /* Pad the header up to the tar block size */ |
@@ -1034,6 +1035,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st | |||
1034 | static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* userData) | 1035 | static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* userData) |
1035 | { | 1036 | { |
1036 | struct TarBallInfo *tbInfo = (struct TarBallInfo *)userData; | 1037 | struct TarBallInfo *tbInfo = (struct TarBallInfo *)userData; |
1038 | const char *header_name; | ||
1037 | #if defined BB_FEATURE_TAR_EXCLUDE | 1039 | #if defined BB_FEATURE_TAR_EXCLUDE |
1038 | char** tmpList; | 1040 | char** tmpList; |
1039 | #endif | 1041 | #endif |
@@ -1069,13 +1071,14 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* | |||
1069 | return( TRUE); | 1071 | return( TRUE); |
1070 | } | 1072 | } |
1071 | 1073 | ||
1072 | while (fileName[0] == '/') { | 1074 | header_name = fileName; |
1075 | while (header_name[0] == '/') { | ||
1073 | static int alreadyWarned=FALSE; | 1076 | static int alreadyWarned=FALSE; |
1074 | if (alreadyWarned==FALSE) { | 1077 | if (alreadyWarned==FALSE) { |
1075 | error_msg("Removing leading '/' from member names\n"); | 1078 | error_msg("Removing leading '/' from member names\n"); |
1076 | alreadyWarned=TRUE; | 1079 | alreadyWarned=TRUE; |
1077 | } | 1080 | } |
1078 | fileName++; | 1081 | header_name++; |
1079 | } | 1082 | } |
1080 | 1083 | ||
1081 | if (strlen(fileName) >= NAME_SIZE) { | 1084 | if (strlen(fileName) >= NAME_SIZE) { |
@@ -1083,7 +1086,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* | |||
1083 | return ( TRUE); | 1086 | return ( TRUE); |
1084 | } | 1087 | } |
1085 | 1088 | ||
1086 | if (fileName[0] == '\0') | 1089 | if (header_name[0] == '\0') |
1087 | return TRUE; | 1090 | return TRUE; |
1088 | 1091 | ||
1089 | #if defined BB_FEATURE_TAR_EXCLUDE | 1092 | #if defined BB_FEATURE_TAR_EXCLUDE |
@@ -1091,7 +1094,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* | |||
1091 | for (tmpList=tbInfo->excludeList; tmpList && *tmpList; tmpList++) { | 1094 | for (tmpList=tbInfo->excludeList; tmpList && *tmpList; tmpList++) { |
1092 | /* Do some extra hoop jumping for when directory names | 1095 | /* Do some extra hoop jumping for when directory names |
1093 | * end in '/' but the entry in tmpList doesn't */ | 1096 | * end in '/' but the entry in tmpList doesn't */ |
1094 | if (strncmp( *tmpList, fileName, strlen(*tmpList))==0 || ( | 1097 | if (strncmp( *tmpList, header_name, strlen(*tmpList))==0 || ( |
1095 | fileName[strlen(fileName)-1]=='/' | 1098 | fileName[strlen(fileName)-1]=='/' |
1096 | && strncmp( *tmpList, fileName, | 1099 | && strncmp( *tmpList, fileName, |
1097 | MIN(strlen(fileName)-1, strlen(*tmpList)))==0)) { | 1100 | MIN(strlen(fileName)-1, strlen(*tmpList)))==0)) { |
@@ -1100,7 +1103,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* | |||
1100 | } | 1103 | } |
1101 | #endif | 1104 | #endif |
1102 | 1105 | ||
1103 | if (writeTarHeader(tbInfo, fileName, statbuf)==FALSE) { | 1106 | if (writeTarHeader(tbInfo, header_name, fileName, statbuf)==FALSE) { |
1104 | return( FALSE); | 1107 | return( FALSE); |
1105 | } | 1108 | } |
1106 | 1109 | ||
@@ -936,7 +936,8 @@ static int putOctal (char *cp, int len, long value) | |||
936 | 936 | ||
937 | /* Write out a tar header for the specified file/directory/whatever */ | 937 | /* Write out a tar header for the specified file/directory/whatever */ |
938 | static int | 938 | static int |
939 | writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *statbuf) | 939 | writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name, |
940 | const char *real_name, struct stat *statbuf) | ||
940 | { | 941 | { |
941 | long chksum=0; | 942 | long chksum=0; |
942 | struct TarHeader header; | 943 | struct TarHeader header; |
@@ -945,7 +946,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st | |||
945 | 946 | ||
946 | memset( &header, 0, size); | 947 | memset( &header, 0, size); |
947 | 948 | ||
948 | strncpy(header.name, fileName, sizeof(header.name)); | 949 | strncpy(header.name, header_name, sizeof(header.name)); |
949 | 950 | ||
950 | putOctal(header.mode, sizeof(header.mode), statbuf->st_mode); | 951 | putOctal(header.mode, sizeof(header.mode), statbuf->st_mode); |
951 | putOctal(header.uid, sizeof(header.uid), statbuf->st_uid); | 952 | putOctal(header.uid, sizeof(header.uid), statbuf->st_uid); |
@@ -971,7 +972,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st | |||
971 | int link_size=0; | 972 | int link_size=0; |
972 | char buffer[BUFSIZ]; | 973 | char buffer[BUFSIZ]; |
973 | header.typeflag = SYMTYPE; | 974 | header.typeflag = SYMTYPE; |
974 | link_size = readlink(fileName, buffer, sizeof(buffer) - 1); | 975 | link_size = readlink(real_name, buffer, sizeof(buffer) - 1); |
975 | if ( link_size < 0) { | 976 | if ( link_size < 0) { |
976 | perror_msg("Error reading symlink '%s'", header.name); | 977 | perror_msg("Error reading symlink '%s'", header.name); |
977 | return ( FALSE); | 978 | return ( FALSE); |
@@ -995,7 +996,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st | |||
995 | header.typeflag = REGTYPE; | 996 | header.typeflag = REGTYPE; |
996 | putOctal(header.size, sizeof(header.size), statbuf->st_size); | 997 | putOctal(header.size, sizeof(header.size), statbuf->st_size); |
997 | } else { | 998 | } else { |
998 | error_msg("%s: Unknown file type\n", fileName); | 999 | error_msg("%s: Unknown file type\n", real_name); |
999 | return ( FALSE); | 1000 | return ( FALSE); |
1000 | } | 1001 | } |
1001 | 1002 | ||
@@ -1012,7 +1013,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st | |||
1012 | 1013 | ||
1013 | /* Now write the header out to disk */ | 1014 | /* Now write the header out to disk */ |
1014 | if ((size=full_write(tbInfo->tarFd, (char*)&header, sizeof(struct TarHeader))) < 0) { | 1015 | if ((size=full_write(tbInfo->tarFd, (char*)&header, sizeof(struct TarHeader))) < 0) { |
1015 | error_msg(io_error, fileName, strerror(errno)); | 1016 | error_msg(io_error, real_name, strerror(errno)); |
1016 | return ( FALSE); | 1017 | return ( FALSE); |
1017 | } | 1018 | } |
1018 | /* Pad the header up to the tar block size */ | 1019 | /* Pad the header up to the tar block size */ |
@@ -1034,6 +1035,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st | |||
1034 | static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* userData) | 1035 | static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* userData) |
1035 | { | 1036 | { |
1036 | struct TarBallInfo *tbInfo = (struct TarBallInfo *)userData; | 1037 | struct TarBallInfo *tbInfo = (struct TarBallInfo *)userData; |
1038 | const char *header_name; | ||
1037 | #if defined BB_FEATURE_TAR_EXCLUDE | 1039 | #if defined BB_FEATURE_TAR_EXCLUDE |
1038 | char** tmpList; | 1040 | char** tmpList; |
1039 | #endif | 1041 | #endif |
@@ -1069,13 +1071,14 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* | |||
1069 | return( TRUE); | 1071 | return( TRUE); |
1070 | } | 1072 | } |
1071 | 1073 | ||
1072 | while (fileName[0] == '/') { | 1074 | header_name = fileName; |
1075 | while (header_name[0] == '/') { | ||
1073 | static int alreadyWarned=FALSE; | 1076 | static int alreadyWarned=FALSE; |
1074 | if (alreadyWarned==FALSE) { | 1077 | if (alreadyWarned==FALSE) { |
1075 | error_msg("Removing leading '/' from member names\n"); | 1078 | error_msg("Removing leading '/' from member names\n"); |
1076 | alreadyWarned=TRUE; | 1079 | alreadyWarned=TRUE; |
1077 | } | 1080 | } |
1078 | fileName++; | 1081 | header_name++; |
1079 | } | 1082 | } |
1080 | 1083 | ||
1081 | if (strlen(fileName) >= NAME_SIZE) { | 1084 | if (strlen(fileName) >= NAME_SIZE) { |
@@ -1083,7 +1086,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* | |||
1083 | return ( TRUE); | 1086 | return ( TRUE); |
1084 | } | 1087 | } |
1085 | 1088 | ||
1086 | if (fileName[0] == '\0') | 1089 | if (header_name[0] == '\0') |
1087 | return TRUE; | 1090 | return TRUE; |
1088 | 1091 | ||
1089 | #if defined BB_FEATURE_TAR_EXCLUDE | 1092 | #if defined BB_FEATURE_TAR_EXCLUDE |
@@ -1091,7 +1094,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* | |||
1091 | for (tmpList=tbInfo->excludeList; tmpList && *tmpList; tmpList++) { | 1094 | for (tmpList=tbInfo->excludeList; tmpList && *tmpList; tmpList++) { |
1092 | /* Do some extra hoop jumping for when directory names | 1095 | /* Do some extra hoop jumping for when directory names |
1093 | * end in '/' but the entry in tmpList doesn't */ | 1096 | * end in '/' but the entry in tmpList doesn't */ |
1094 | if (strncmp( *tmpList, fileName, strlen(*tmpList))==0 || ( | 1097 | if (strncmp( *tmpList, header_name, strlen(*tmpList))==0 || ( |
1095 | fileName[strlen(fileName)-1]=='/' | 1098 | fileName[strlen(fileName)-1]=='/' |
1096 | && strncmp( *tmpList, fileName, | 1099 | && strncmp( *tmpList, fileName, |
1097 | MIN(strlen(fileName)-1, strlen(*tmpList)))==0)) { | 1100 | MIN(strlen(fileName)-1, strlen(*tmpList)))==0)) { |
@@ -1100,7 +1103,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* | |||
1100 | } | 1103 | } |
1101 | #endif | 1104 | #endif |
1102 | 1105 | ||
1103 | if (writeTarHeader(tbInfo, fileName, statbuf)==FALSE) { | 1106 | if (writeTarHeader(tbInfo, header_name, fileName, statbuf)==FALSE) { |
1104 | return( FALSE); | 1107 | return( FALSE); |
1105 | } | 1108 | } |
1106 | 1109 | ||