diff options
author | Matt Kraai <kraai@debian.org> | 2000-09-04 08:25:42 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2000-09-04 08:25:42 +0000 |
commit | b92223b6f5848b2cdb41c3a6b9261b47826a5816 (patch) | |
tree | 1e3243c5a24394b6c3a1030c44ee5394947862bf | |
parent | fd50c3d2f9ab76aaf3736090e278be8742155d9f (diff) | |
download | busybox-w32-b92223b6f5848b2cdb41c3a6b9261b47826a5816.tar.gz busybox-w32-b92223b6f5848b2cdb41c3a6b9261b47826a5816.tar.bz2 busybox-w32-b92223b6f5848b2cdb41c3a6b9261b47826a5816.zip |
Allow selective extraction and listing of files. And fix an unchecked
return value of realloc (with xrealloc).
-rw-r--r-- | archival/tar.c | 31 | ||||
-rw-r--r-- | tar.c | 31 |
2 files changed, 54 insertions, 8 deletions
diff --git a/archival/tar.c b/archival/tar.c index 460962e44..d3b0e5c0a 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -125,7 +125,8 @@ typedef struct TarInfo TarInfo; | |||
125 | 125 | ||
126 | /* Local procedures to restore files from a tar file. */ | 126 | /* Local procedures to restore files from a tar file. */ |
127 | static int readTarFile(const char* tarName, int extractFlag, int listFlag, | 127 | static int readTarFile(const char* tarName, int extractFlag, int listFlag, |
128 | int tostdoutFlag, int verboseFlag, char** excludeList); | 128 | int tostdoutFlag, int verboseFlag, char** extractList, |
129 | char** excludeList); | ||
129 | 130 | ||
130 | 131 | ||
131 | 132 | ||
@@ -190,7 +191,7 @@ extern int tar_main(int argc, char **argv) | |||
190 | if (strcmp(optarg, "exclude")==0) { | 191 | if (strcmp(optarg, "exclude")==0) { |
191 | if (argv[optind]==NULL) | 192 | if (argv[optind]==NULL) |
192 | fatalError( "option `--exclude' requires an argument\n"); | 193 | fatalError( "option `--exclude' requires an argument\n"); |
193 | excludeList=realloc( excludeList, sizeof(char**) * (excludeListSize+2)); | 194 | excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2)); |
194 | excludeList[excludeListSize] = argv[optind]; | 195 | excludeList[excludeListSize] = argv[optind]; |
195 | /* Remove leading "/"s */ | 196 | /* Remove leading "/"s */ |
196 | if (*excludeList[excludeListSize] =='/') { | 197 | if (*excludeList[excludeListSize] =='/') { |
@@ -222,7 +223,7 @@ extern int tar_main(int argc, char **argv) | |||
222 | #endif | 223 | #endif |
223 | } | 224 | } |
224 | if (listFlag == TRUE || extractFlag == TRUE) { | 225 | if (listFlag == TRUE || extractFlag == TRUE) { |
225 | exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag, excludeList)); | 226 | exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag, &argv[optind], excludeList)); |
226 | } | 227 | } |
227 | 228 | ||
228 | flagError: | 229 | flagError: |
@@ -477,7 +478,8 @@ readTarHeader(struct TarHeader *rawHeader, struct TarInfo *header) | |||
477 | * If the list is empty than all files are extracted or listed. | 478 | * If the list is empty than all files are extracted or listed. |
478 | */ | 479 | */ |
479 | static int readTarFile(const char* tarName, int extractFlag, int listFlag, | 480 | static int readTarFile(const char* tarName, int extractFlag, int listFlag, |
480 | int tostdoutFlag, int verboseFlag, char** excludeList) | 481 | int tostdoutFlag, int verboseFlag, char** extractList, |
482 | char** excludeList) | ||
481 | { | 483 | { |
482 | int status, tarFd=-1; | 484 | int status, tarFd=-1; |
483 | int errorFlag=FALSE; | 485 | int errorFlag=FALSE; |
@@ -544,6 +546,27 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag, | |||
544 | continue; | 546 | continue; |
545 | } | 547 | } |
546 | #endif | 548 | #endif |
549 | if (*extractList != NULL) { | ||
550 | int skipFlag = TRUE; | ||
551 | for (tmpList = extractList; *tmpList != NULL; tmpList++) { | ||
552 | if (strncmp( *tmpList, header.name, strlen(*tmpList))==0 || ( | ||
553 | header.name[strlen(header.name)-1]=='/' | ||
554 | && strncmp( *tmpList, header.name, | ||
555 | MIN(strlen(header.name)-1, strlen(*tmpList)))==0)) { | ||
556 | /* If it is a regular file, pretend to extract it with | ||
557 | * the extractFlag set to FALSE, so the junk in the tarball | ||
558 | * is properly skipped over */ | ||
559 | skipFlag = FALSE; | ||
560 | break; | ||
561 | } | ||
562 | } | ||
563 | /* There are not the droids you're looking for, move along */ | ||
564 | if (skipFlag == TRUE) { | ||
565 | if ( header.type==REGTYPE || header.type==REGTYPE0 ) | ||
566 | tarExtractRegularFile(&header, FALSE, FALSE); | ||
567 | continue; | ||
568 | } | ||
569 | } | ||
547 | /* Special treatment if the list (-t) flag is on */ | 570 | /* Special treatment if the list (-t) flag is on */ |
548 | if (verboseFlag == TRUE && extractFlag == FALSE) { | 571 | if (verboseFlag == TRUE && extractFlag == FALSE) { |
549 | int len, len1; | 572 | int len, len1; |
@@ -125,7 +125,8 @@ typedef struct TarInfo TarInfo; | |||
125 | 125 | ||
126 | /* Local procedures to restore files from a tar file. */ | 126 | /* Local procedures to restore files from a tar file. */ |
127 | static int readTarFile(const char* tarName, int extractFlag, int listFlag, | 127 | static int readTarFile(const char* tarName, int extractFlag, int listFlag, |
128 | int tostdoutFlag, int verboseFlag, char** excludeList); | 128 | int tostdoutFlag, int verboseFlag, char** extractList, |
129 | char** excludeList); | ||
129 | 130 | ||
130 | 131 | ||
131 | 132 | ||
@@ -190,7 +191,7 @@ extern int tar_main(int argc, char **argv) | |||
190 | if (strcmp(optarg, "exclude")==0) { | 191 | if (strcmp(optarg, "exclude")==0) { |
191 | if (argv[optind]==NULL) | 192 | if (argv[optind]==NULL) |
192 | fatalError( "option `--exclude' requires an argument\n"); | 193 | fatalError( "option `--exclude' requires an argument\n"); |
193 | excludeList=realloc( excludeList, sizeof(char**) * (excludeListSize+2)); | 194 | excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2)); |
194 | excludeList[excludeListSize] = argv[optind]; | 195 | excludeList[excludeListSize] = argv[optind]; |
195 | /* Remove leading "/"s */ | 196 | /* Remove leading "/"s */ |
196 | if (*excludeList[excludeListSize] =='/') { | 197 | if (*excludeList[excludeListSize] =='/') { |
@@ -222,7 +223,7 @@ extern int tar_main(int argc, char **argv) | |||
222 | #endif | 223 | #endif |
223 | } | 224 | } |
224 | if (listFlag == TRUE || extractFlag == TRUE) { | 225 | if (listFlag == TRUE || extractFlag == TRUE) { |
225 | exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag, excludeList)); | 226 | exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag, &argv[optind], excludeList)); |
226 | } | 227 | } |
227 | 228 | ||
228 | flagError: | 229 | flagError: |
@@ -477,7 +478,8 @@ readTarHeader(struct TarHeader *rawHeader, struct TarInfo *header) | |||
477 | * If the list is empty than all files are extracted or listed. | 478 | * If the list is empty than all files are extracted or listed. |
478 | */ | 479 | */ |
479 | static int readTarFile(const char* tarName, int extractFlag, int listFlag, | 480 | static int readTarFile(const char* tarName, int extractFlag, int listFlag, |
480 | int tostdoutFlag, int verboseFlag, char** excludeList) | 481 | int tostdoutFlag, int verboseFlag, char** extractList, |
482 | char** excludeList) | ||
481 | { | 483 | { |
482 | int status, tarFd=-1; | 484 | int status, tarFd=-1; |
483 | int errorFlag=FALSE; | 485 | int errorFlag=FALSE; |
@@ -544,6 +546,27 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag, | |||
544 | continue; | 546 | continue; |
545 | } | 547 | } |
546 | #endif | 548 | #endif |
549 | if (*extractList != NULL) { | ||
550 | int skipFlag = TRUE; | ||
551 | for (tmpList = extractList; *tmpList != NULL; tmpList++) { | ||
552 | if (strncmp( *tmpList, header.name, strlen(*tmpList))==0 || ( | ||
553 | header.name[strlen(header.name)-1]=='/' | ||
554 | && strncmp( *tmpList, header.name, | ||
555 | MIN(strlen(header.name)-1, strlen(*tmpList)))==0)) { | ||
556 | /* If it is a regular file, pretend to extract it with | ||
557 | * the extractFlag set to FALSE, so the junk in the tarball | ||
558 | * is properly skipped over */ | ||
559 | skipFlag = FALSE; | ||
560 | break; | ||
561 | } | ||
562 | } | ||
563 | /* There are not the droids you're looking for, move along */ | ||
564 | if (skipFlag == TRUE) { | ||
565 | if ( header.type==REGTYPE || header.type==REGTYPE0 ) | ||
566 | tarExtractRegularFile(&header, FALSE, FALSE); | ||
567 | continue; | ||
568 | } | ||
569 | } | ||
547 | /* Special treatment if the list (-t) flag is on */ | 570 | /* Special treatment if the list (-t) flag is on */ |
548 | if (verboseFlag == TRUE && extractFlag == FALSE) { | 571 | if (verboseFlag == TRUE && extractFlag == FALSE) { |
549 | int len, len1; | 572 | int len, len1; |