summaryrefslogtreecommitdiff
path: root/chmod_chown_chgrp.c
diff options
context:
space:
mode:
authorMark Whitley2000-06-06 18:11:46 +0000
committerMark Whitley2000-06-06 18:11:46 +0000
commiteec2f63b3f6117256e0d8f328e40a63bcab84bb4 (patch)
tree1eeede271ebd51afa911ebd2493e066aa781f764 /chmod_chown_chgrp.c
parent700a5aed75dca84eba1714aa44d698283be68d63 (diff)
downloadbusybox-eec2f63b3f6117256e0d8f328e40a63bcab84bb4.zip
busybox-eec2f63b3f6117256e0d8f328e40a63bcab84bb4.tar.gz
Fixed segfaults for "chown -R" and "chgrp -R". Also added a message for "too
few arguments".
Diffstat (limited to 'chmod_chown_chgrp.c')
-rw-r--r--chmod_chown_chgrp.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/chmod_chown_chgrp.c b/chmod_chown_chgrp.c
index c0e380a..a3af4fb 100644
--- a/chmod_chown_chgrp.c
+++ b/chmod_chown_chgrp.c
@@ -25,6 +25,7 @@
#include "internal.h"
#define BB_DECLARE_EXTERN
#define bb_need_invalid_option
+#define bb_need_too_few_args
#include "messages.c"
#include <stdio.h>
@@ -114,24 +115,27 @@ int chmod_chown_chgrp_main(int argc, char **argv)
if (argc < 2)
usage(appUsage);
invocationName = *argv;
- argc--;
argv++;
/* Parse options */
- while (argc && (**argv == '-')) {
+ while (--argc >= 0 && *argv && (**argv == '-')) {
while (*++(*argv))
switch (**argv) {
- case 'R':
- recursiveFlag = TRUE;
- break;
- default:
- fprintf(stderr, invalid_option, invocationName, **argv);
- usage(appUsage);
+ case 'R':
+ recursiveFlag = TRUE;
+ break;
+ default:
+ fprintf(stderr, invalid_option, invocationName, **argv);
+ usage(appUsage);
}
- argc--;
argv++;
}
+ if (argc == 0 || *argv == NULL) {
+ fprintf(stderr, too_few_args, invocationName);
+ usage(appUsage);
+ }
+
if (whichApp == CHMOD_APP) {
theMode = *argv;
} else {