aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Whitley <markw@lineo.com>2000-06-06 18:11:46 +0000
committerMark Whitley <markw@lineo.com>2000-06-06 18:11:46 +0000
commiteec2f63b3f6117256e0d8f328e40a63bcab84bb4 (patch)
tree1eeede271ebd51afa911ebd2493e066aa781f764
parent700a5aed75dca84eba1714aa44d698283be68d63 (diff)
downloadbusybox-w32-eec2f63b3f6117256e0d8f328e40a63bcab84bb4.tar.gz
busybox-w32-eec2f63b3f6117256e0d8f328e40a63bcab84bb4.tar.bz2
busybox-w32-eec2f63b3f6117256e0d8f328e40a63bcab84bb4.zip
Fixed segfaults for "chown -R" and "chgrp -R". Also added a message for "too
few arguments".
-rw-r--r--chmod_chown_chgrp.c22
-rw-r--r--messages.c3
2 files changed, 16 insertions, 9 deletions
diff --git a/chmod_chown_chgrp.c b/chmod_chown_chgrp.c
index c0e380a8e..a3af4fbb3 100644
--- a/chmod_chown_chgrp.c
+++ b/chmod_chown_chgrp.c
@@ -25,6 +25,7 @@
25#include "internal.h" 25#include "internal.h"
26#define BB_DECLARE_EXTERN 26#define BB_DECLARE_EXTERN
27#define bb_need_invalid_option 27#define bb_need_invalid_option
28#define bb_need_too_few_args
28#include "messages.c" 29#include "messages.c"
29 30
30#include <stdio.h> 31#include <stdio.h>
@@ -114,24 +115,27 @@ int chmod_chown_chgrp_main(int argc, char **argv)
114 if (argc < 2) 115 if (argc < 2)
115 usage(appUsage); 116 usage(appUsage);
116 invocationName = *argv; 117 invocationName = *argv;
117 argc--;
118 argv++; 118 argv++;
119 119
120 /* Parse options */ 120 /* Parse options */
121 while (argc && (**argv == '-')) { 121 while (--argc >= 0 && *argv && (**argv == '-')) {
122 while (*++(*argv)) 122 while (*++(*argv))
123 switch (**argv) { 123 switch (**argv) {
124 case 'R': 124 case 'R':
125 recursiveFlag = TRUE; 125 recursiveFlag = TRUE;
126 break; 126 break;
127 default: 127 default:
128 fprintf(stderr, invalid_option, invocationName, **argv); 128 fprintf(stderr, invalid_option, invocationName, **argv);
129 usage(appUsage); 129 usage(appUsage);
130 } 130 }
131 argc--;
132 argv++; 131 argv++;
133 } 132 }
134 133
134 if (argc == 0 || *argv == NULL) {
135 fprintf(stderr, too_few_args, invocationName);
136 usage(appUsage);
137 }
138
135 if (whichApp == CHMOD_APP) { 139 if (whichApp == CHMOD_APP) {
136 theMode = *argv; 140 theMode = *argv;
137 } else { 141 } else {
diff --git a/messages.c b/messages.c
index 2f8aab515..cb8de4077 100644
--- a/messages.c
+++ b/messages.c
@@ -74,6 +74,9 @@
74#if defined bb_need_write_error || ! defined BB_DECLARE_EXTERN 74#if defined bb_need_write_error || ! defined BB_DECLARE_EXTERN
75 BB_DEF_MESSAGE(write_error, "Write Error\n") 75 BB_DEF_MESSAGE(write_error, "Write Error\n")
76#endif 76#endif
77#if defined bb_need_too_few_args || ! defined BB_DECLARE_EXTERN
78 BB_DEF_MESSAGE(too_few_args, "%s: too few arguments\n")
79#endif
77 80
78 81
79 82