Fixed tar option parsing segfault, and make "tar xv" and "tar -xv"

both work (i.e. it works with or w/o the "-").
 -Erik
This commit is contained in:
Eric Andersen 2000-05-30 19:05:57 +00:00
parent e511e7c116
commit 108a44345c
3 changed files with 10 additions and 10 deletions

View File

@ -16,10 +16,8 @@
* Fixed ping warnings -- fix from Sascha Ziemann <szi@aibon.ping.de> * Fixed ping warnings -- fix from Sascha Ziemann <szi@aibon.ping.de>
* Fixed update segfault * Fixed update segfault
* Fixed mknod -- minor number was always 0 * Fixed mknod -- minor number was always 0
* Fixed tar option parsing. In an attempt to accomodate the whiners * Fixed tar option parsing, so both "tar xvf foo.tar" and "tar -xvf foo.tar"
that wanted "tar cf foo.tar foo" (i.e. no "-" before options) now work (i.e. no "-" before options) (this was very broken in 0.43).
I broke creation of tarballs. I reverted the change (so tar needs
the "-" for all options).
* Several contributions from Randolph Chung <tausq@debian.org>. * Several contributions from Randolph Chung <tausq@debian.org>.
* cp/mv now accepts the -f flag * cp/mv now accepts the -f flag
* tail can now accept -<num> commands (e.g. -10) for better * tail can now accept -<num> commands (e.g. -10) for better

View File

@ -173,7 +173,7 @@ extern int tar_main(int argc, char **argv)
#if defined BB_FEATURE_TAR_EXCLUDE #if defined BB_FEATURE_TAR_EXCLUDE
int excludeListSize=0; int excludeListSize=0;
#endif #endif
const char *tarName=NULL; const char *tarName="-";
int listFlag = FALSE; int listFlag = FALSE;
int extractFlag = FALSE; int extractFlag = FALSE;
int createFlag = FALSE; int createFlag = FALSE;
@ -187,13 +187,13 @@ extern int tar_main(int argc, char **argv)
/* Parse any options */ /* Parse any options */
while (--argc > 0 && strspn(*(++argv), "-cxt") >0 ) { while (--argc > 0 && strspn(*(++argv), "-cxt") >0 ) {
stopIt=FALSE; stopIt=FALSE;
while (stopIt==FALSE && *(++(*argv))) { while (stopIt==FALSE && *argv && **argv) {
switch (**argv) { switch (**argv) {
case 'f': case 'f':
if (--argc == 0) { if (--argc == 0) {
fatalError( "Option requires an argument: No file specified\n"); fatalError( "Option requires an argument: No file specified\n");
} }
if (tarName != NULL) if (*tarName != '-')
fatalError( "Only one 'f' option allowed\n"); fatalError( "Only one 'f' option allowed\n");
tarName = *(++argv); tarName = *(++argv);
if (tarName == NULL) if (tarName == NULL)
@ -252,6 +252,7 @@ extern int tar_main(int argc, char **argv)
fatalError( "Unknown tar flag '%c'\n" fatalError( "Unknown tar flag '%c'\n"
"Try `tar --help' for more information\n", **argv); "Try `tar --help' for more information\n", **argv);
} }
++(*argv);
} }
} }

7
tar.c
View File

@ -173,7 +173,7 @@ extern int tar_main(int argc, char **argv)
#if defined BB_FEATURE_TAR_EXCLUDE #if defined BB_FEATURE_TAR_EXCLUDE
int excludeListSize=0; int excludeListSize=0;
#endif #endif
const char *tarName=NULL; const char *tarName="-";
int listFlag = FALSE; int listFlag = FALSE;
int extractFlag = FALSE; int extractFlag = FALSE;
int createFlag = FALSE; int createFlag = FALSE;
@ -187,13 +187,13 @@ extern int tar_main(int argc, char **argv)
/* Parse any options */ /* Parse any options */
while (--argc > 0 && strspn(*(++argv), "-cxt") >0 ) { while (--argc > 0 && strspn(*(++argv), "-cxt") >0 ) {
stopIt=FALSE; stopIt=FALSE;
while (stopIt==FALSE && *(++(*argv))) { while (stopIt==FALSE && *argv && **argv) {
switch (**argv) { switch (**argv) {
case 'f': case 'f':
if (--argc == 0) { if (--argc == 0) {
fatalError( "Option requires an argument: No file specified\n"); fatalError( "Option requires an argument: No file specified\n");
} }
if (tarName != NULL) if (*tarName != '-')
fatalError( "Only one 'f' option allowed\n"); fatalError( "Only one 'f' option allowed\n");
tarName = *(++argv); tarName = *(++argv);
if (tarName == NULL) if (tarName == NULL)
@ -252,6 +252,7 @@ extern int tar_main(int argc, char **argv)
fatalError( "Unknown tar flag '%c'\n" fatalError( "Unknown tar flag '%c'\n"
"Try `tar --help' for more information\n", **argv); "Try `tar --help' for more information\n", **argv);
} }
++(*argv);
} }
} }