diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-10-25 00:33:44 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-10-25 00:33:44 +0000 |
commit | 7488dd85691d795666d82ff00f803bbdd92e5f5d (patch) | |
tree | 4aa28c4440e6c150a31188f1910b6a945176c27c /libbb | |
parent | 638961ee5247785217bb67aa6d5e27886e5dfab0 (diff) | |
download | busybox-w32-7488dd85691d795666d82ff00f803bbdd92e5f5d.tar.gz busybox-w32-7488dd85691d795666d82ff00f803bbdd92e5f5d.tar.bz2 busybox-w32-7488dd85691d795666d82ff00f803bbdd92e5f5d.zip |
wget: wget $'-\207' ... should not be allowed to work. ever. :)
So fix wget & getopt32. Also fix multiple --header options
order: add and use rev_llist.
git-svn-id: svn://busybox.net/trunk/busybox@16433 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/getopt32.c | 40 | ||||
-rw-r--r-- | libbb/llist.c | 14 |
2 files changed, 34 insertions, 20 deletions
diff --git a/libbb/getopt32.c b/libbb/getopt32.c index 73e6b8684..967729a1b 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c | |||
@@ -313,7 +313,7 @@ getopt32(int argc, char **argv, const char *applet_opts, ...) | |||
313 | { | 313 | { |
314 | unsigned flags = 0; | 314 | unsigned flags = 0; |
315 | unsigned requires = 0; | 315 | unsigned requires = 0; |
316 | t_complementary complementary[sizeof(flags) * 8 + 1]; | 316 | t_complementary complementary[33]; |
317 | int c; | 317 | int c; |
318 | const unsigned char *s; | 318 | const unsigned char *s; |
319 | t_complementary *on_off; | 319 | t_complementary *on_off; |
@@ -342,16 +342,13 @@ getopt32(int argc, char **argv, const char *applet_opts, ...) | |||
342 | s = (const unsigned char *)applet_opts; | 342 | s = (const unsigned char *)applet_opts; |
343 | if (*s == '+' || *s == '-') | 343 | if (*s == '+' || *s == '-') |
344 | s++; | 344 | s++; |
345 | for (; *s; s++) { | 345 | while (*s) { |
346 | if (c >= (int)(sizeof(flags)*8)) | 346 | if (c >= 32) break; |
347 | break; | ||
348 | on_off->opt = *s; | 347 | on_off->opt = *s; |
349 | on_off->switch_on = (1 << c); | 348 | on_off->switch_on = (1 << c); |
350 | if (s[1] == ':') { | 349 | if (*++s == ':') { |
351 | on_off->optarg = va_arg(p, void **); | 350 | on_off->optarg = va_arg(p, void **); |
352 | do | 351 | while (*++s == ':') /* skip */; |
353 | s++; | ||
354 | while (s[1] == ':'); | ||
355 | } | 352 | } |
356 | on_off++; | 353 | on_off++; |
357 | c++; | 354 | c++; |
@@ -363,16 +360,14 @@ getopt32(int argc, char **argv, const char *applet_opts, ...) | |||
363 | continue; | 360 | continue; |
364 | for (on_off = complementary; on_off->opt != 0; on_off++) | 361 | for (on_off = complementary; on_off->opt != 0; on_off++) |
365 | if (on_off->opt == l_o->val) | 362 | if (on_off->opt == l_o->val) |
366 | break; | 363 | goto next_long; |
367 | if (on_off->opt == 0) { | 364 | if (c >= 32) break; |
368 | if (c >= (int)(sizeof(flags)*8)) | 365 | on_off->opt = l_o->val; |
369 | break; | 366 | on_off->switch_on = (1 << c); |
370 | on_off->opt = l_o->val; | 367 | if (l_o->has_arg != no_argument) |
371 | on_off->switch_on = (1 << c); | 368 | on_off->optarg = va_arg(p, void **); |
372 | if (l_o->has_arg != no_argument) | 369 | c++; |
373 | on_off->optarg = va_arg(p, void **); | 370 | next_long: ; |
374 | c++; | ||
375 | } | ||
376 | } | 371 | } |
377 | #endif /* ENABLE_GETOPT_LONG */ | 372 | #endif /* ENABLE_GETOPT_LONG */ |
378 | for (s = (const unsigned char *)opt_complementary; s && *s; s++) { | 373 | for (s = (const unsigned char *)opt_complementary; s && *s; s++) { |
@@ -461,12 +456,17 @@ getopt32(int argc, char **argv, const char *applet_opts, ...) | |||
461 | } | 456 | } |
462 | } | 457 | } |
463 | #endif | 458 | #endif |
459 | /* Note: just "getopt() <= 0" will not work good for | ||
460 | * "fake" short options, like this one: | ||
461 | * wget $'-\203' "Test: test" http://kernel.org/ | ||
462 | * (supposed to act as --header, but doesn't) */ | ||
464 | #if ENABLE_GETOPT_LONG | 463 | #if ENABLE_GETOPT_LONG |
465 | while ((c = getopt_long(argc, argv, applet_opts, | 464 | while ((c = getopt_long(argc, argv, applet_opts, |
466 | applet_long_options, NULL)) >= 0) { | 465 | applet_long_options, NULL)) != -1) { |
467 | #else | 466 | #else |
468 | while ((c = getopt(argc, argv, applet_opts)) >= 0) { | 467 | while ((c = getopt(argc, argv, applet_opts)) != -1) { |
469 | #endif /* ENABLE_GETOPT_LONG */ | 468 | #endif /* ENABLE_GETOPT_LONG */ |
469 | c &= 0xff; /* fight libc's sign extends */ | ||
470 | loop_arg_is_opt: | 470 | loop_arg_is_opt: |
471 | for (on_off = complementary; on_off->opt != c; on_off++) { | 471 | for (on_off = complementary; on_off->opt != c; on_off++) { |
472 | /* c==0 if long opt have non NULL flag */ | 472 | /* c==0 if long opt have non NULL flag */ |
diff --git a/libbb/llist.c b/libbb/llist.c index 8bf89a595..8a74832ee 100644 --- a/libbb/llist.c +++ b/libbb/llist.c | |||
@@ -62,3 +62,17 @@ void llist_free(llist_t *elm, void (*freeit)(void *data)) | |||
62 | if (freeit) freeit(data); | 62 | if (freeit) freeit(data); |
63 | } | 63 | } |
64 | } | 64 | } |
65 | |||
66 | /* Reverse list order. Useful since getopt32 saves option params | ||
67 | * in reverse order */ | ||
68 | llist_t* rev_llist(llist_t *list) | ||
69 | { | ||
70 | llist_t *new = NULL; | ||
71 | while (list) { | ||
72 | llist_t *next = list->link; | ||
73 | list->link = new; | ||
74 | new = list; | ||
75 | list = next; | ||
76 | } | ||
77 | return new; | ||
78 | } | ||