diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-27 23:23:41 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-27 23:23:41 +0100 |
| commit | 9107b63a7fb80fcab0da71cf12e8c81dfc394d20 (patch) | |
| tree | 566be6323a69a09949110349e720e33d7dd66fb2 | |
| parent | c2fdd41f5f97349f23b2a66592b9b29834faabaf (diff) | |
| download | busybox-w32-9107b63a7fb80fcab0da71cf12e8c81dfc394d20.tar.gz busybox-w32-9107b63a7fb80fcab0da71cf12e8c81dfc394d20.tar.bz2 busybox-w32-9107b63a7fb80fcab0da71cf12e8c81dfc394d20.zip | |
udhcp: abort if we see unknown option, and show valid options if so
function old new delta
udhcp_option_idx - 77 +77
udhcp_str2optset 366 351 -15
udhcpc_main 2845 2801 -44
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 77/-59) Total: 18 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | networking/udhcp/common.c | 26 | ||||
| -rw-r--r-- | networking/udhcp/common.h | 2 | ||||
| -rw-r--r-- | networking/udhcp/dhcpc.c | 10 |
3 files changed, 26 insertions, 12 deletions
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 9316774ff..6e8ec3e64 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c | |||
| @@ -146,6 +146,25 @@ static void log_option(const char *pfx, const uint8_t *opt) | |||
| 146 | # define log_option(pfx, opt) ((void)0) | 146 | # define log_option(pfx, opt) ((void)0) |
| 147 | #endif | 147 | #endif |
| 148 | 148 | ||
| 149 | unsigned FAST_FUNC udhcp_option_idx(const char *name) | ||
| 150 | { | ||
| 151 | int n = index_in_strings(dhcp_option_strings, name); | ||
| 152 | if (n >= 0) | ||
| 153 | return n; | ||
| 154 | |||
| 155 | { | ||
| 156 | char buf[sizeof(dhcp_option_strings)]; | ||
| 157 | char *d = buf; | ||
| 158 | const char *s = dhcp_option_strings; | ||
| 159 | while (s < dhcp_option_strings + sizeof(dhcp_option_strings) - 2) { | ||
| 160 | *d++ = (*s == '\0' ? ' ' : *s); | ||
| 161 | s++; | ||
| 162 | } | ||
| 163 | *d = '\0'; | ||
| 164 | bb_error_msg_and_die("unknown option '%s', known options: %s", name, buf); | ||
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 149 | /* get an option with bounds checking (warning, result is not aligned). */ | 168 | /* get an option with bounds checking (warning, result is not aligned). */ |
| 150 | uint8_t* FAST_FUNC udhcp_get_option(struct dhcp_packet *packet, int code) | 169 | uint8_t* FAST_FUNC udhcp_get_option(struct dhcp_packet *packet, int code) |
| 151 | { | 170 | { |
| @@ -372,7 +391,7 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg) | |||
| 372 | char *opt, *val, *endptr; | 391 | char *opt, *val, *endptr; |
| 373 | char *str; | 392 | char *str; |
| 374 | const struct dhcp_option *option; | 393 | const struct dhcp_option *option; |
| 375 | int retval, length, idx; | 394 | int retval, length; |
| 376 | char buffer[8] ALIGNED(4); | 395 | char buffer[8] ALIGNED(4); |
| 377 | uint16_t *result_u16 = (uint16_t *) buffer; | 396 | uint16_t *result_u16 = (uint16_t *) buffer; |
| 378 | uint32_t *result_u32 = (uint32_t *) buffer; | 397 | uint32_t *result_u32 = (uint32_t *) buffer; |
| @@ -383,10 +402,7 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg) | |||
| 383 | if (!opt) | 402 | if (!opt) |
| 384 | return 0; | 403 | return 0; |
| 385 | 404 | ||
| 386 | idx = index_in_strings(dhcp_option_strings, opt); /* NB: was strcasecmp! */ | 405 | option = &dhcp_options[udhcp_option_idx(opt)]; |
| 387 | if (idx < 0) | ||
| 388 | return 0; | ||
| 389 | option = &dhcp_options[idx]; | ||
| 390 | 406 | ||
| 391 | retval = 0; | 407 | retval = 0; |
| 392 | do { | 408 | do { |
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index b4e8b5d43..1c5afa6f9 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h | |||
| @@ -169,6 +169,8 @@ extern const struct dhcp_option dhcp_options[]; | |||
| 169 | extern const char dhcp_option_strings[]; | 169 | extern const char dhcp_option_strings[]; |
| 170 | extern const uint8_t dhcp_option_lengths[]; | 170 | extern const uint8_t dhcp_option_lengths[]; |
| 171 | 171 | ||
| 172 | unsigned FAST_FUNC udhcp_option_idx(const char *name); | ||
| 173 | |||
| 172 | uint8_t *udhcp_get_option(struct dhcp_packet *packet, int code) FAST_FUNC; | 174 | uint8_t *udhcp_get_option(struct dhcp_packet *packet, int code) FAST_FUNC; |
| 173 | int udhcp_end_option(uint8_t *optionptr) FAST_FUNC; | 175 | int udhcp_end_option(uint8_t *optionptr) FAST_FUNC; |
| 174 | void udhcp_add_binary_option(struct dhcp_packet *packet, uint8_t *addopt) FAST_FUNC; | 176 | void udhcp_add_binary_option(struct dhcp_packet *packet, uint8_t *addopt) FAST_FUNC; |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 478ca5c21..c36d4180b 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
| @@ -879,21 +879,17 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
| 879 | client_config.no_default_options = 1; | 879 | client_config.no_default_options = 1; |
| 880 | while (list_O) { | 880 | while (list_O) { |
| 881 | char *optstr = llist_pop(&list_O); | 881 | char *optstr = llist_pop(&list_O); |
| 882 | int n = index_in_strings(dhcp_option_strings, optstr); | 882 | unsigned n = udhcp_option_idx(optstr); |
| 883 | if (n < 0) | ||
| 884 | bb_error_msg_and_die("unknown option '%s'", optstr); | ||
| 885 | n = dhcp_options[n].code; | 883 | n = dhcp_options[n].code; |
| 886 | client_config.opt_mask[n >> 3] |= 1 << (n & 7); | 884 | client_config.opt_mask[n >> 3] |= 1 << (n & 7); |
| 887 | } | 885 | } |
| 888 | while (list_x) { | 886 | while (list_x) { |
| 889 | int n; | 887 | unsigned n; |
| 890 | char *optstr = llist_pop(&list_x); | 888 | char *optstr = llist_pop(&list_x); |
| 891 | char *colon = strchr(optstr, ':'); | 889 | char *colon = strchr(optstr, ':'); |
| 892 | if (colon) | 890 | if (colon) |
| 893 | *colon = '\0'; | 891 | *colon = '\0'; |
| 894 | n = index_in_strings(dhcp_option_strings, optstr); | 892 | n = udhcp_option_idx(optstr); |
| 895 | if (n < 0) | ||
| 896 | bb_error_msg_and_die("unknown option '%s'", optstr); | ||
| 897 | if (colon) | 893 | if (colon) |
| 898 | *colon = ' '; | 894 | *colon = ' '; |
| 899 | udhcp_str2optset(optstr, &client_config.options); | 895 | udhcp_str2optset(optstr, &client_config.options); |
