aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2000-11-08 02:35:47 +0000
committerMatt Kraai <kraai@debian.org>2000-11-08 02:35:47 +0000
commitd8ad76cb31ff7c4b2d97cc66eafc4297f5cea7d7 (patch)
tree96d2607e6ec898a68b746d65df0eac88281be77c
parent63a862272cc5c0cc8e15c8d95dfb9e8944eb944e (diff)
downloadbusybox-w32-d8ad76cb31ff7c4b2d97cc66eafc4297f5cea7d7.tar.gz
busybox-w32-d8ad76cb31ff7c4b2d97cc66eafc4297f5cea7d7.tar.bz2
busybox-w32-d8ad76cb31ff7c4b2d97cc66eafc4297f5cea7d7.zip
Fix some bugs reported by Jim Gleason <jimg@lineo.com> and others I
introduced.
-rw-r--r--archival/tar.c39
-rw-r--r--tar.c39
2 files changed, 30 insertions, 48 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 740462eb3..4fd864b25 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -137,8 +137,8 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
137 137
138#ifdef BB_FEATURE_TAR_CREATE 138#ifdef BB_FEATURE_TAR_CREATE
139/* Local procedures to save files into a tar file. */ 139/* Local procedures to save files into a tar file. */
140static int writeTarFile(const char* tarName, int tostdoutFlag, 140static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
141 int verboseFlag, int argc, char **argv, char** excludeList); 141 char** excludeList);
142#endif 142#endif
143 143
144extern int tar_main(int argc, char **argv) 144extern int tar_main(int argc, char **argv)
@@ -160,13 +160,11 @@ extern int tar_main(int argc, char **argv)
160 if (argc <= 1) 160 if (argc <= 1)
161 usage(tar_usage); 161 usage(tar_usage);
162 162
163 /* do normal option parsing */ 163 while (*(++argv) && (**argv == '-' || firstOpt == TRUE)) {
164 while (--argc > 0 && ((*argv && **(++argv) == '-') ||
165 (firstOpt==TRUE && strspn(*argv, "-cxt") ))) {
166 firstOpt=FALSE; 164 firstOpt=FALSE;
167 stopIt=FALSE; 165 stopIt=FALSE;
168 while (stopIt==FALSE && *argv && **argv) { 166 while (stopIt==FALSE && **argv) {
169 switch (**argv) { 167 switch (*((*argv)++)) {
170 case 'c': 168 case 'c':
171 if (extractFlag == TRUE || listFlag == TRUE) 169 if (extractFlag == TRUE || listFlag == TRUE)
172 goto flagError; 170 goto flagError;
@@ -187,29 +185,22 @@ extern int tar_main(int argc, char **argv)
187 break; 185 break;
188 case 'O': 186 case 'O':
189 tostdoutFlag = TRUE; 187 tostdoutFlag = TRUE;
190 tarName = "-";
191 break; 188 break;
192 case 'f': 189 case 'f':
193 if (--argc == 0) {
194 fatalError( "Option requires an argument: No file specified\n");
195 }
196 if (*tarName != '-') 190 if (*tarName != '-')
197 fatalError( "Only one 'f' option allowed\n"); 191 fatalError( "Only one 'f' option allowed\n");
198 tarName = *(++argv); 192 tarName = *(++argv);
199 if (tarName == NULL) 193 if (tarName == NULL)
200 fatalError( "Option requires an argument: No file specified\n"); 194 fatalError( "Option requires an argument: No file specified\n");
201 if (!strcmp(tarName, "-") && createFlag == TRUE)
202 tostdoutFlag = TRUE;
203 stopIt=TRUE; 195 stopIt=TRUE;
204 break; 196 break;
205#if defined BB_FEATURE_TAR_EXCLUDE 197#if defined BB_FEATURE_TAR_EXCLUDE
206 case 'e': 198 case 'e':
207 if (strcmp(*argv, "exclude")==0) { 199 if (strcmp(*argv, "exclude")==0) {
208 if (--argc == 0) {
209 fatalError( "Option requires an argument: No file specified\n");
210 }
211 excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2)); 200 excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2));
212 excludeList[excludeListSize] = *(++argv); 201 excludeList[excludeListSize] = *(++argv);
202 if (excludeList[excludeListSize] == NULL)
203 fatalError( "Option requires an argument: No file specified\n");
213 /* Remove leading "/"s */ 204 /* Remove leading "/"s */
214 if (*excludeList[excludeListSize] =='/') 205 if (*excludeList[excludeListSize] =='/')
215 excludeList[excludeListSize] = (excludeList[excludeListSize])+1; 206 excludeList[excludeListSize] = (excludeList[excludeListSize])+1;
@@ -224,7 +215,6 @@ extern int tar_main(int argc, char **argv)
224 default: 215 default:
225 usage(tar_usage); 216 usage(tar_usage);
226 } 217 }
227 ++(*argv);
228 } 218 }
229 } 219 }
230 220
@@ -236,11 +226,12 @@ extern int tar_main(int argc, char **argv)
236#ifndef BB_FEATURE_TAR_CREATE 226#ifndef BB_FEATURE_TAR_CREATE
237 fatalError( "This version of tar was not compiled with tar creation support.\n"); 227 fatalError( "This version of tar was not compiled with tar creation support.\n");
238#else 228#else
239 exit(writeTarFile(tarName, tostdoutFlag, verboseFlag, argc, argv, excludeList)); 229 exit(writeTarFile(tarName, verboseFlag, argv, excludeList));
240#endif 230#endif
241 } 231 }
242 if (listFlag == TRUE || extractFlag == TRUE) { 232 if (listFlag == TRUE || extractFlag == TRUE) {
243 exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag, &argv[optind], excludeList)); 233 exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag,
234 verboseFlag, argv, excludeList));
244 } 235 }
245 236
246 flagError: 237 flagError:
@@ -967,8 +958,8 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void*
967 return( TRUE); 958 return( TRUE);
968} 959}
969 960
970static int writeTarFile(const char* tarName, int tostdoutFlag, 961static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
971 int verboseFlag, int argc, char **argv, char** excludeList) 962 char** excludeList)
972{ 963{
973 int tarFd=-1; 964 int tarFd=-1;
974 int errorFlag=FALSE; 965 int errorFlag=FALSE;
@@ -977,11 +968,11 @@ static int writeTarFile(const char* tarName, int tostdoutFlag,
977 tbInfo.verboseFlag = verboseFlag; 968 tbInfo.verboseFlag = verboseFlag;
978 969
979 /* Make sure there is at least one file to tar up. */ 970 /* Make sure there is at least one file to tar up. */
980 if (argc <= 0) 971 if (*argv == NULL)
981 fatalError("Cowardly refusing to create an empty archive\n"); 972 fatalError("Cowardly refusing to create an empty archive\n");
982 973
983 /* Open the tar file for writing. */ 974 /* Open the tar file for writing. */
984 if (tostdoutFlag == TRUE) 975 if (!strcmp(tarName, "-"))
985 tbInfo.tarFd = fileno(stdout); 976 tbInfo.tarFd = fileno(stdout);
986 else 977 else
987 tbInfo.tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644); 978 tbInfo.tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644);
@@ -1000,7 +991,7 @@ static int writeTarFile(const char* tarName, int tostdoutFlag,
1000 umask(0); 991 umask(0);
1001 992
1002 /* Read the directory/files and iterate over them one at a time */ 993 /* Read the directory/files and iterate over them one at a time */
1003 while (argc-- > 0) { 994 while (*argv != NULL) {
1004 if (recursiveAction(*argv++, TRUE, FALSE, FALSE, 995 if (recursiveAction(*argv++, TRUE, FALSE, FALSE,
1005 writeFileToTarball, writeFileToTarball, 996 writeFileToTarball, writeFileToTarball,
1006 (void*) &tbInfo) == FALSE) { 997 (void*) &tbInfo) == FALSE) {
diff --git a/tar.c b/tar.c
index 740462eb3..4fd864b25 100644
--- a/tar.c
+++ b/tar.c
@@ -137,8 +137,8 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
137 137
138#ifdef BB_FEATURE_TAR_CREATE 138#ifdef BB_FEATURE_TAR_CREATE
139/* Local procedures to save files into a tar file. */ 139/* Local procedures to save files into a tar file. */
140static int writeTarFile(const char* tarName, int tostdoutFlag, 140static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
141 int verboseFlag, int argc, char **argv, char** excludeList); 141 char** excludeList);
142#endif 142#endif
143 143
144extern int tar_main(int argc, char **argv) 144extern int tar_main(int argc, char **argv)
@@ -160,13 +160,11 @@ extern int tar_main(int argc, char **argv)
160 if (argc <= 1) 160 if (argc <= 1)
161 usage(tar_usage); 161 usage(tar_usage);
162 162
163 /* do normal option parsing */ 163 while (*(++argv) && (**argv == '-' || firstOpt == TRUE)) {
164 while (--argc > 0 && ((*argv && **(++argv) == '-') ||
165 (firstOpt==TRUE && strspn(*argv, "-cxt") ))) {
166 firstOpt=FALSE; 164 firstOpt=FALSE;
167 stopIt=FALSE; 165 stopIt=FALSE;
168 while (stopIt==FALSE && *argv && **argv) { 166 while (stopIt==FALSE && **argv) {
169 switch (**argv) { 167 switch (*((*argv)++)) {
170 case 'c': 168 case 'c':
171 if (extractFlag == TRUE || listFlag == TRUE) 169 if (extractFlag == TRUE || listFlag == TRUE)
172 goto flagError; 170 goto flagError;
@@ -187,29 +185,22 @@ extern int tar_main(int argc, char **argv)
187 break; 185 break;
188 case 'O': 186 case 'O':
189 tostdoutFlag = TRUE; 187 tostdoutFlag = TRUE;
190 tarName = "-";
191 break; 188 break;
192 case 'f': 189 case 'f':
193 if (--argc == 0) {
194 fatalError( "Option requires an argument: No file specified\n");
195 }
196 if (*tarName != '-') 190 if (*tarName != '-')
197 fatalError( "Only one 'f' option allowed\n"); 191 fatalError( "Only one 'f' option allowed\n");
198 tarName = *(++argv); 192 tarName = *(++argv);
199 if (tarName == NULL) 193 if (tarName == NULL)
200 fatalError( "Option requires an argument: No file specified\n"); 194 fatalError( "Option requires an argument: No file specified\n");
201 if (!strcmp(tarName, "-") && createFlag == TRUE)
202 tostdoutFlag = TRUE;
203 stopIt=TRUE; 195 stopIt=TRUE;
204 break; 196 break;
205#if defined BB_FEATURE_TAR_EXCLUDE 197#if defined BB_FEATURE_TAR_EXCLUDE
206 case 'e': 198 case 'e':
207 if (strcmp(*argv, "exclude")==0) { 199 if (strcmp(*argv, "exclude")==0) {
208 if (--argc == 0) {
209 fatalError( "Option requires an argument: No file specified\n");
210 }
211 excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2)); 200 excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2));
212 excludeList[excludeListSize] = *(++argv); 201 excludeList[excludeListSize] = *(++argv);
202 if (excludeList[excludeListSize] == NULL)
203 fatalError( "Option requires an argument: No file specified\n");
213 /* Remove leading "/"s */ 204 /* Remove leading "/"s */
214 if (*excludeList[excludeListSize] =='/') 205 if (*excludeList[excludeListSize] =='/')
215 excludeList[excludeListSize] = (excludeList[excludeListSize])+1; 206 excludeList[excludeListSize] = (excludeList[excludeListSize])+1;
@@ -224,7 +215,6 @@ extern int tar_main(int argc, char **argv)
224 default: 215 default:
225 usage(tar_usage); 216 usage(tar_usage);
226 } 217 }
227 ++(*argv);
228 } 218 }
229 } 219 }
230 220
@@ -236,11 +226,12 @@ extern int tar_main(int argc, char **argv)
236#ifndef BB_FEATURE_TAR_CREATE 226#ifndef BB_FEATURE_TAR_CREATE
237 fatalError( "This version of tar was not compiled with tar creation support.\n"); 227 fatalError( "This version of tar was not compiled with tar creation support.\n");
238#else 228#else
239 exit(writeTarFile(tarName, tostdoutFlag, verboseFlag, argc, argv, excludeList)); 229 exit(writeTarFile(tarName, verboseFlag, argv, excludeList));
240#endif 230#endif
241 } 231 }
242 if (listFlag == TRUE || extractFlag == TRUE) { 232 if (listFlag == TRUE || extractFlag == TRUE) {
243 exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag, &argv[optind], excludeList)); 233 exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag,
234 verboseFlag, argv, excludeList));
244 } 235 }
245 236
246 flagError: 237 flagError:
@@ -967,8 +958,8 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void*
967 return( TRUE); 958 return( TRUE);
968} 959}
969 960
970static int writeTarFile(const char* tarName, int tostdoutFlag, 961static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
971 int verboseFlag, int argc, char **argv, char** excludeList) 962 char** excludeList)
972{ 963{
973 int tarFd=-1; 964 int tarFd=-1;
974 int errorFlag=FALSE; 965 int errorFlag=FALSE;
@@ -977,11 +968,11 @@ static int writeTarFile(const char* tarName, int tostdoutFlag,
977 tbInfo.verboseFlag = verboseFlag; 968 tbInfo.verboseFlag = verboseFlag;
978 969
979 /* Make sure there is at least one file to tar up. */ 970 /* Make sure there is at least one file to tar up. */
980 if (argc <= 0) 971 if (*argv == NULL)
981 fatalError("Cowardly refusing to create an empty archive\n"); 972 fatalError("Cowardly refusing to create an empty archive\n");
982 973
983 /* Open the tar file for writing. */ 974 /* Open the tar file for writing. */
984 if (tostdoutFlag == TRUE) 975 if (!strcmp(tarName, "-"))
985 tbInfo.tarFd = fileno(stdout); 976 tbInfo.tarFd = fileno(stdout);
986 else 977 else
987 tbInfo.tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644); 978 tbInfo.tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644);
@@ -1000,7 +991,7 @@ static int writeTarFile(const char* tarName, int tostdoutFlag,
1000 umask(0); 991 umask(0);
1001 992
1002 /* Read the directory/files and iterate over them one at a time */ 993 /* Read the directory/files and iterate over them one at a time */
1003 while (argc-- > 0) { 994 while (*argv != NULL) {
1004 if (recursiveAction(*argv++, TRUE, FALSE, FALSE, 995 if (recursiveAction(*argv++, TRUE, FALSE, FALSE,
1005 writeFileToTarball, writeFileToTarball, 996 writeFileToTarball, writeFileToTarball,
1006 (void*) &tbInfo) == FALSE) { 997 (void*) &tbInfo) == FALSE) {