Fixed segfaults for "chown -R" and "chgrp -R". Also added a message for "too

few arguments".
This commit is contained in:
Mark Whitley 2000-06-06 18:11:46 +00:00
parent 700a5aed75
commit eec2f63b3f
2 changed files with 16 additions and 9 deletions

View File

@ -25,6 +25,7 @@
#include "internal.h" #include "internal.h"
#define BB_DECLARE_EXTERN #define BB_DECLARE_EXTERN
#define bb_need_invalid_option #define bb_need_invalid_option
#define bb_need_too_few_args
#include "messages.c" #include "messages.c"
#include <stdio.h> #include <stdio.h>
@ -114,24 +115,27 @@ int chmod_chown_chgrp_main(int argc, char **argv)
if (argc < 2) if (argc < 2)
usage(appUsage); usage(appUsage);
invocationName = *argv; invocationName = *argv;
argc--;
argv++; argv++;
/* Parse options */ /* Parse options */
while (argc && (**argv == '-')) { while (--argc >= 0 && *argv && (**argv == '-')) {
while (*++(*argv)) while (*++(*argv))
switch (**argv) { switch (**argv) {
case 'R': case 'R':
recursiveFlag = TRUE; recursiveFlag = TRUE;
break; break;
default: default:
fprintf(stderr, invalid_option, invocationName, **argv); fprintf(stderr, invalid_option, invocationName, **argv);
usage(appUsage); usage(appUsage);
} }
argc--;
argv++; argv++;
} }
if (argc == 0 || *argv == NULL) {
fprintf(stderr, too_few_args, invocationName);
usage(appUsage);
}
if (whichApp == CHMOD_APP) { if (whichApp == CHMOD_APP) {
theMode = *argv; theMode = *argv;
} else { } else {

View File

@ -74,6 +74,9 @@
#if defined bb_need_write_error || ! defined BB_DECLARE_EXTERN #if defined bb_need_write_error || ! defined BB_DECLARE_EXTERN
BB_DEF_MESSAGE(write_error, "Write Error\n") BB_DEF_MESSAGE(write_error, "Write Error\n")
#endif #endif
#if defined bb_need_too_few_args || ! defined BB_DECLARE_EXTERN
BB_DEF_MESSAGE(too_few_args, "%s: too few arguments\n")
#endif