Fixed segfaults for "chown -R" and "chgrp -R". Also added a message for "too
authorMark Whitley <markw@lineo.com>
Tue, 6 Jun 2000 18:11:46 +0000 (18:11 -0000)
committerMark Whitley <markw@lineo.com>
Tue, 6 Jun 2000 18:11:46 +0000 (18:11 -0000)
few arguments".

chmod_chown_chgrp.c
messages.c

index c0e380a8ebc7451e5ed1ad19e10167babf60e94f..a3af4fbb3f36fb79653cc386c5618c43db573d9d 100644 (file)
@@ -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 {
index 2f8aab5155ac3dd72a7eae037976a0cf9b1c2943..cb8de4077bef23c7309e85802334330840857ae5 100644 (file)
@@ -74,6 +74,9 @@
 #if defined bb_need_write_error || ! defined BB_DECLARE_EXTERN
        BB_DEF_MESSAGE(write_error, "Write Error\n")
 #endif
+#if defined bb_need_too_few_args || ! defined BB_DECLARE_EXTERN
+       BB_DEF_MESSAGE(too_few_args, "%s: too few arguments\n")
+#endif