diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2013-01-13 22:09:39 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2013-01-13 22:09:39 +0000 |
commit | a90d9482cf493267b048ac28ccf91318c51bfdf2 (patch) | |
tree | a0cd27616a07f5cd95d2864ba0e6bb2f7386b554 /sbin/dhclient/options.c | |
parent | 3aff13d026f23ec68d9fc2a91e5b19712e9be71c (diff) |
Make pretty_print_option() return "" rather than "<fmt error>" when
the option fails validation tests. Make pretty_print_option() bail
on all bad format strings, and on all incorrect option data lengths.
Check pretty_print_option() return value rather than repeating
validation with check_option(). Do res_hnok() check on host name,
domain name, and nis domain while creating lease from packet info.
As a result, nuke ipv4addrs() and check_option().
Ignore options that do not validate rather than summarily rejecting
offered lease. Treat all options whose names start with "option-"
as unknown rather than relying on a big switch on DHO_ names.
Started when reading dhclient(8) -u verbiage.
Diffstat (limited to 'sbin/dhclient/options.c')
-rw-r--r-- | sbin/dhclient/options.c | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c index 261e1aadbca..3ce831ccc67 100644 --- a/sbin/dhclient/options.c +++ b/sbin/dhclient/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.45 2012/11/15 14:54:18 krw Exp $ */ +/* $OpenBSD: options.c,v 1.46 2013/01/13 22:09:38 krw Exp $ */ /* DHCP options parsing and reassembly. */ @@ -209,9 +209,13 @@ pretty_print_option(unsigned int code, struct option_data *option, struct in_addr foo; char comma; + memset(optbuf, 0, sizeof(optbuf)); + /* Code should be between 0 and 255. */ - if (code > 255) - error("pretty_print_option: bad code %d", code); + if (code > 255) { + warning("pretty_print_option: bad code %d", code); + goto done; + } if (emit_punct) comma = ','; @@ -224,7 +228,7 @@ pretty_print_option(unsigned int code, struct option_data *option, warning("%s: Excess information in format string: %s", dhcp_options[code].name, &(dhcp_options[code].format[i])); - break; + goto done; } numelem++; fmtbuf[i] = dhcp_options[code].format[i]; @@ -238,7 +242,7 @@ pretty_print_option(unsigned int code, struct option_data *option, " in format string: %s", dhcp_options[code].name, dhcp_options[code].format); - return ("<fmt error>"); + goto done; } break; case 'X': @@ -282,7 +286,7 @@ pretty_print_option(unsigned int code, struct option_data *option, warning("%s: garbage in format string: %s", dhcp_options[code].name, &(dhcp_options[code].format[i])); - break; + goto done; } } @@ -290,20 +294,24 @@ pretty_print_option(unsigned int code, struct option_data *option, if (hunksize > len) { warning("%s: expecting at least %d bytes; got %d", dhcp_options[code].name, hunksize, len); - return ("<error>"); + goto done; } /* Check for too many bytes... */ - if (numhunk == -1 && hunksize < len) + if (numhunk == -1 && hunksize < len) { warning("%s: %d extra bytes", dhcp_options[code].name, len - hunksize); + goto done; + } /* If this is an array, compute its size. */ if (!numhunk) numhunk = len / hunksize; /* See if we got an exact number of hunks. */ - if (numhunk > 0 && numhunk * hunksize < len) - warning("%s: %d extra bytes at end of array", - dhcp_options[code].name, len - numhunk * hunksize); + if (numhunk > 0 && numhunk * hunksize != len) { + warning("%s: expecting %d bytes: got %d", + dhcp_options[code].name, numhunk * hunksize, len); + goto done; + } /* A one-hunk array prints the same as a single hunk. */ if (numhunk < 0) @@ -439,10 +447,13 @@ pretty_print_option(unsigned int code, struct option_data *option, goto toobig; } + +done: + return (optbuf); + +toobig: + memset(optbuf, 0, sizeof(optbuf)); return (optbuf); - toobig: - warning("dhcp option too large"); - return ("<error>"); } void |