aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/common.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-03-27 23:23:41 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-03-27 23:23:41 +0100
commit9107b63a7fb80fcab0da71cf12e8c81dfc394d20 (patch)
tree566be6323a69a09949110349e720e33d7dd66fb2 /networking/udhcp/common.c
parentc2fdd41f5f97349f23b2a66592b9b29834faabaf (diff)
downloadbusybox-9107b63a7fb80fcab0da71cf12e8c81dfc394d20.tar.gz
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>
Diffstat (limited to 'networking/udhcp/common.c')
-rw-r--r--networking/udhcp/common.c26
1 files changed, 21 insertions, 5 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)
# define log_option(pfx, opt) ((void)0)
#endif
+unsigned FAST_FUNC udhcp_option_idx(const char *name)
+{
+ int n = index_in_strings(dhcp_option_strings, name);
+ if (n >= 0)
+ return n;
+
+ {
+ char buf[sizeof(dhcp_option_strings)];
+ char *d = buf;
+ const char *s = dhcp_option_strings;
+ while (s < dhcp_option_strings + sizeof(dhcp_option_strings) - 2) {
+ *d++ = (*s == '\0' ? ' ' : *s);
+ s++;
+ }
+ *d = '\0';
+ bb_error_msg_and_die("unknown option '%s', known options: %s", name, buf);
+ }
+}
+
/* get an option with bounds checking (warning, result is not aligned). */
uint8_t* FAST_FUNC udhcp_get_option(struct dhcp_packet *packet, int code)
{
@@ -372,7 +391,7 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg)
char *opt, *val, *endptr;
char *str;
const struct dhcp_option *option;
- int retval, length, idx;
+ int retval, length;
char buffer[8] ALIGNED(4);
uint16_t *result_u16 = (uint16_t *) buffer;
uint32_t *result_u32 = (uint32_t *) buffer;
@@ -383,10 +402,7 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg)
if (!opt)
return 0;
- idx = index_in_strings(dhcp_option_strings, opt); /* NB: was strcasecmp! */
- if (idx < 0)
- return 0;
- option = &dhcp_options[idx];
+ option = &dhcp_options[udhcp_option_idx(opt)];
retval = 0;
do {