From 5f51b7b385ca5b628c4c361761217aa1fe34b412 Mon Sep 17 00:00:00 2001 From: dumbbell Date: Fri, 30 Dec 2011 14:33:08 +0000 Subject: Invalid Domain Search option isn't considered as a fatal error In the original Domain Search option patch, an invalid option value would cause the whole lease to be rejected. However, DHCP servers who emit such an invalid value are more common than I thought. With this new patch, just the option is rejected, not the entire lease. PR: bin/163431 Submitted by: Fabian Keil (earlier version) Reviewed by: Fabian Keil Sponsored by: Yakaz (http://www.yakaz.com) --- sbin/dhclient/options.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'sbin') diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c index 3f87028..17643e7 100644 --- a/sbin/dhclient/options.c +++ b/sbin/dhclient/options.c @@ -211,7 +211,7 @@ parse_option_buffer(struct packet *packet, void expand_domain_search(struct packet *packet) { - int offset, expanded_len; + int offset, expanded_len, next_domain_len; struct option_data *option; unsigned char *domain_search, *cursor; @@ -224,9 +224,13 @@ expand_domain_search(struct packet *packet) expanded_len = 0; offset = 0; while (offset < option->len) { + next_domain_len = find_search_domain_name_len(option, &offset); + if (next_domain_len < 0) + /* The Domain Search option value is invalid. */ + return; + /* We add 1 for the space between domain names. */ - expanded_len += - find_search_domain_name_len(option, &offset) + 1; + expanded_len += next_domain_len + 1; } if (expanded_len > 0) /* Remove 1 for the superfluous trailing space. */ @@ -271,8 +275,9 @@ find_search_domain_name_len(struct option_data *option, int *offset) /* This is a pointer to another list of labels. */ if (i + 1 >= option->len) { /* The pointer is truncated. */ - error("Truncated pointer in DHCP Domain " + warning("Truncated pointer in DHCP Domain " "Search option."); + return (-1); } pointer = ((label_len & ~(0xC0)) << 8) + @@ -282,8 +287,9 @@ find_search_domain_name_len(struct option_data *option, int *offset) * The pointer must indicates a prior * occurance. */ - error("Invalid forward pointer in DHCP Domain " - "Search option compression."); + warning("Invalid forward pointer in DHCP " + "Domain Search option compression."); + return (-1); } pointed_len = find_search_domain_name_len(option, @@ -295,7 +301,9 @@ find_search_domain_name_len(struct option_data *option, int *offset) } if (i + label_len >= option->len) { - error("Truncated label in DHCP Domain Search option."); + warning("Truncated label in DHCP Domain Search " + "option."); + return (-1); } /* @@ -308,9 +316,9 @@ find_search_domain_name_len(struct option_data *option, int *offset) i += label_len + 1; } - error("Truncated DHCP Domain Search option."); + warning("Truncated DHCP Domain Search option."); - return (0); + return (-1); } void -- cgit v1.1