diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-11-24 21:54:44 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-11-24 21:54:44 +0000 |
commit | 60c4e3b6e69e35898351b1fa6bdd7f20ea371fa9 (patch) | |
tree | 26f4426eba02d3b7f22da62ef3af151a89c99e3f /libbb | |
parent | 89026b9951b21f7b660f8d0c5e5a7aee9344fd45 (diff) | |
download | busybox-w32-60c4e3b6e69e35898351b1fa6bdd7f20ea371fa9.tar.gz busybox-w32-60c4e3b6e69e35898351b1fa6bdd7f20ea371fa9.tar.bz2 busybox-w32-60c4e3b6e69e35898351b1fa6bdd7f20ea371fa9.zip |
tar: sanitize option handling
git-svn-id: svn://busybox.net/trunk/busybox@16661 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/getopt32.c | 68 | ||||
-rw-r--r-- | libbb/mtab_file.c | 4 | ||||
-rw-r--r-- | libbb/procps.c | 64 | ||||
-rw-r--r-- | libbb/safe_strtol.c | 42 |
4 files changed, 88 insertions, 90 deletions
diff --git a/libbb/getopt32.c b/libbb/getopt32.c index f442933a3..dddf8121a 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c | |||
@@ -147,6 +147,40 @@ const char *opt_complementary | |||
147 | 147 | ||
148 | Special characters: | 148 | Special characters: |
149 | 149 | ||
150 | "-" A dash as the first char in a opt_complementary group forces | ||
151 | all arguments to be treated as options, even if they have | ||
152 | no leading dashes. Next char in this case can't be a digit (0-9), | ||
153 | use ':' or end of line. For example: | ||
154 | |||
155 | opt_complementary = "-:w-x:x-w"; | ||
156 | getopt32(argc, argv, "wx"); | ||
157 | |||
158 | Allows any arguments to be given without a dash (./program w x) | ||
159 | as well as with a dash (./program -x). | ||
160 | |||
161 | "--" A double dash at the beginning of opt_complementary means the | ||
162 | argv[1] string should always be treated as options, even if it isn't | ||
163 | prefixed with a "-". This is useful for special syntax in applets | ||
164 | such as "ar" and "tar": | ||
165 | tar xvf foo.tar | ||
166 | |||
167 | "-N" A dash as the first char in a opt_complementary group followed | ||
168 | by a single digit (0-9) means that at least N non-option | ||
169 | arguments must be present on the command line | ||
170 | |||
171 | "=N" An equal sign as the first char in a opt_complementary group followed | ||
172 | by a single digit (0-9) means that exactly N non-option | ||
173 | arguments must be present on the command line | ||
174 | |||
175 | "?N" A "?" as the first char in a opt_complementary group followed | ||
176 | by a single digit (0-9) means that at most N arguments must be present | ||
177 | on the command line. | ||
178 | |||
179 | "V-" An option with dash before colon or end-of-line results in | ||
180 | bb_show_usage being called if this option is encountered. | ||
181 | This is typically used to implement "print verbose usage message | ||
182 | and exit" option. | ||
183 | |||
150 | "-" A dash between two options causes the second of the two | 184 | "-" A dash between two options causes the second of the two |
151 | to be unset (and ignored) if it is given on the command line. | 185 | to be unset (and ignored) if it is given on the command line. |
152 | 186 | ||
@@ -173,30 +207,6 @@ Special characters: | |||
173 | if (opt & 4) | 207 | if (opt & 4) |
174 | printf("Detected odd -x usage\n"); | 208 | printf("Detected odd -x usage\n"); |
175 | 209 | ||
176 | "-" A dash as the first char in a opt_complementary group forces | ||
177 | all arguments to be treated as options, even if they have | ||
178 | no leading dashes. Next char in this case can't be a digit (0-9), | ||
179 | use ':' or end of line. For example: | ||
180 | |||
181 | opt_complementary = "-:w-x:x-w"; | ||
182 | getopt32(argc, argv, "wx"); | ||
183 | |||
184 | Allows any arguments to be given without a dash (./program w x) | ||
185 | as well as with a dash (./program -x). | ||
186 | |||
187 | "-N" A dash as the first char in a opt_complementary group followed | ||
188 | by a single digit (0-9) means that at least N non-option | ||
189 | arguments must be present on the command line | ||
190 | |||
191 | "=N" An equal sign as the first char in a opt_complementary group followed | ||
192 | by a single digit (0-9) means that exactly N non-option | ||
193 | arguments must be present on the command line | ||
194 | |||
195 | "V-" An option with dash before colon or end-of-line results in | ||
196 | bb_show_usage being called if this option is encountered. | ||
197 | This is typically used to implement "print verbose usage message | ||
198 | and exit" option. | ||
199 | |||
200 | "--" A double dash between two options, or between an option and a group | 210 | "--" A double dash between two options, or between an option and a group |
201 | of options, means that they are mutually exclusive. Unlike | 211 | of options, means that they are mutually exclusive. Unlike |
202 | the "-" case above, an error will be forced if the options | 212 | the "-" case above, an error will be forced if the options |
@@ -221,10 +231,6 @@ Special characters: | |||
221 | if BB_GETOPT_ERROR is detected, don't return, call bb_show_usage | 231 | if BB_GETOPT_ERROR is detected, don't return, call bb_show_usage |
222 | and exit instead. Next char after '?' can't be a digit. | 232 | and exit instead. Next char after '?' can't be a digit. |
223 | 233 | ||
224 | "?N" A "?" as the first char in a opt_complementary group followed | ||
225 | by a single digit (0-9) means that at most N arguments must be present | ||
226 | on the command line. | ||
227 | |||
228 | "::" A double colon after a char in opt_complementary means that the | 234 | "::" A double colon after a char in opt_complementary means that the |
229 | option can occur multiple times. Each occurrence will be saved as | 235 | option can occur multiple times. Each occurrence will be saved as |
230 | a llist_t element instead of char*. | 236 | a llist_t element instead of char*. |
@@ -245,12 +251,6 @@ Special characters: | |||
245 | root:x:0:0:root:/root:/bin/bash | 251 | root:x:0:0:root:/root:/bin/bash |
246 | user:x:500:500::/home/user:/bin/bash | 252 | user:x:500:500::/home/user:/bin/bash |
247 | 253 | ||
248 | "--" A double dash at the beginning of opt_complementary means the | ||
249 | argv[1] string should always be treated as options, even if it isn't | ||
250 | prefixed with a "-". This is useful for special syntax in applets | ||
251 | such as "ar" and "tar": | ||
252 | tar xvf foo.tar | ||
253 | |||
254 | "?" An "?" between an option and a group of options means that | 254 | "?" An "?" between an option and a group of options means that |
255 | at least one of them is required to occur if the first option | 255 | at least one of them is required to occur if the first option |
256 | occurs in preceding command line arguments. | 256 | occurs in preceding command line arguments. |
diff --git a/libbb/mtab_file.c b/libbb/mtab_file.c index 3181d6d58..67367e3d7 100644 --- a/libbb/mtab_file.c +++ b/libbb/mtab_file.c | |||
@@ -13,5 +13,5 @@ | |||
13 | 13 | ||
14 | /* Busybox mount uses either /proc/mounts or /etc/mtab to | 14 | /* Busybox mount uses either /proc/mounts or /etc/mtab to |
15 | * get the list of currently mounted filesystems */ | 15 | * get the list of currently mounted filesystems */ |
16 | const char bb_path_mtab_file[] = USE_FEATURE_MTAB_SUPPORT("/etc/mtab") | 16 | const char bb_path_mtab_file[] = |
17 | SKIP_FEATURE_MTAB_SUPPORT("/proc/mounts"); | 17 | USE_FEATURE_MTAB_SUPPORT("/etc/mtab")SKIP_FEATURE_MTAB_SUPPORT("/proc/mounts"); |
diff --git a/libbb/procps.c b/libbb/procps.c index 2581d03b2..ee4f5e53f 100644 --- a/libbb/procps.c +++ b/libbb/procps.c | |||
@@ -216,39 +216,39 @@ procps_status_t* procps_scan(procps_status_t* sp, int flags) | |||
216 | } | 216 | } |
217 | /* from kernel: | 217 | /* from kernel: |
218 | // pid comm S ppid pgid sid tty_nr tty_pgrp flg | 218 | // pid comm S ppid pgid sid tty_nr tty_pgrp flg |
219 | sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \ | 219 | sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \ |
220 | %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \ | 220 | %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \ |
221 | %lu %lu %lu %lu %lu %lu %lu %lu %d %d %lu %lu %llu\n", | 221 | %lu %lu %lu %lu %lu %lu %lu %lu %d %d %lu %lu %llu\n", |
222 | task->pid, | 222 | task->pid, |
223 | tcomm, | 223 | tcomm, |
224 | state, | 224 | state, |
225 | ppid, | 225 | ppid, |
226 | pgid, | 226 | pgid, |
227 | sid, | 227 | sid, |
228 | tty_nr, | 228 | tty_nr, |
229 | tty_pgrp, | 229 | tty_pgrp, |
230 | task->flags, | 230 | task->flags, |
231 | min_flt, | 231 | min_flt, |
232 | 232 | ||
233 | cmin_flt, | 233 | cmin_flt, |
234 | maj_flt, | 234 | maj_flt, |
235 | cmaj_flt, | 235 | cmaj_flt, |
236 | cputime_to_clock_t(utime), | 236 | cputime_to_clock_t(utime), |
237 | cputime_to_clock_t(stime), | 237 | cputime_to_clock_t(stime), |
238 | cputime_to_clock_t(cutime), | 238 | cputime_to_clock_t(cutime), |
239 | cputime_to_clock_t(cstime), | 239 | cputime_to_clock_t(cstime), |
240 | priority, | 240 | priority, |
241 | nice, | 241 | nice, |
242 | num_threads, | 242 | num_threads, |
243 | // 0, | 243 | // 0, |
244 | start_time, | 244 | start_time, |
245 | vsize, | 245 | vsize, |
246 | mm ? get_mm_rss(mm) : 0, | 246 | mm ? get_mm_rss(mm) : 0, |
247 | rsslim, | 247 | rsslim, |
248 | mm ? mm->start_code : 0, | 248 | mm ? mm->start_code : 0, |
249 | mm ? mm->end_code : 0, | 249 | mm ? mm->end_code : 0, |
250 | mm ? mm->start_stack : 0, | 250 | mm ? mm->start_stack : 0, |
251 | esp, | 251 | esp, |
252 | eip, | 252 | eip, |
253 | the rest is some obsolete cruft | 253 | the rest is some obsolete cruft |
254 | */ | 254 | */ |
diff --git a/libbb/safe_strtol.c b/libbb/safe_strtol.c index a7f012fbc..d3bb29cdd 100644 --- a/libbb/safe_strtol.c +++ b/libbb/safe_strtol.c | |||
@@ -102,40 +102,38 @@ int safe_strtol(const char *arg, long* value) | |||
102 | 102 | ||
103 | # define strong_alias(name, aliasname) _strong_alias (name, aliasname) | 103 | # define strong_alias(name, aliasname) _strong_alias (name, aliasname) |
104 | # define _strong_alias(name, aliasname) \ | 104 | # define _strong_alias(name, aliasname) \ |
105 | __asm__(".global " __C_SYMBOL_PREFIX__ #aliasname "\n" \ | 105 | __asm__(".global " __C_SYMBOL_PREFIX__ #aliasname "\n" \ |
106 | ".set " __C_SYMBOL_PREFIX__ #aliasname "," __C_SYMBOL_PREFIX__ #name); | 106 | ".set " __C_SYMBOL_PREFIX__ #aliasname "," __C_SYMBOL_PREFIX__ #name); |
107 | 107 | ||
108 | #endif | 108 | #endif |
109 | #endif | 109 | #endif |
110 | 110 | ||
111 | int safe_strtoi(const char *arg, int* value) | 111 | int safe_strtoi(const char *arg, int* value) |
112 | { | 112 | { |
113 | if (sizeof(long) == sizeof(int)) { | 113 | int error; |
114 | long lvalue; | ||
115 | if (sizeof(long) == sizeof(int)) | ||
114 | return safe_strtol(arg, (long*)value); | 116 | return safe_strtol(arg, (long*)value); |
115 | } else { | 117 | lvalue = *value; |
116 | int error; | 118 | error = safe_strtol(arg, &lvalue); |
117 | long lvalue = *value; | 119 | if (lvalue < INT_MIN || lvalue > INT_MAX) |
118 | error = safe_strtol(arg, &lvalue); | 120 | return 1; |
119 | if (lvalue < INT_MIN || lvalue > INT_MAX) | 121 | *value = (int) lvalue; |
120 | return 1; | 122 | return error; |
121 | *value = (int) lvalue; | ||
122 | return error; | ||
123 | } | ||
124 | } | 123 | } |
125 | 124 | ||
126 | int safe_strtou(const char *arg, unsigned* value) | 125 | int safe_strtou(const char *arg, unsigned* value) |
127 | { | 126 | { |
128 | if (sizeof(unsigned long) == sizeof(unsigned)) { | 127 | int error; |
128 | unsigned long lvalue; | ||
129 | if (sizeof(unsigned long) == sizeof(unsigned)) | ||
129 | return safe_strtoul(arg, (unsigned long*)value); | 130 | return safe_strtoul(arg, (unsigned long*)value); |
130 | } else { | 131 | lvalue = *value; |
131 | int error; | 132 | error = safe_strtoul(arg, &lvalue); |
132 | unsigned long lvalue = *value; | 133 | if (lvalue > UINT_MAX) |
133 | error = safe_strtoul(arg, &lvalue); | 134 | return 1; |
134 | if (lvalue > UINT_MAX) | 135 | *value = (unsigned) lvalue; |
135 | return 1; | 136 | return error; |
136 | *value = (unsigned) lvalue; | ||
137 | return error; | ||
138 | } | ||
139 | } | 137 | } |
140 | 138 | ||
141 | int BUG_safe_strtou32_unimplemented(void); | 139 | int BUG_safe_strtou32_unimplemented(void); |