From: Hans Dedecker Date: Fri, 19 Apr 2019 11:16:58 +0000 (+0200) Subject: router: fix dns search list option X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=6633efeb8196853503305c2714ba6830c8d9c70b;p=oweals%2Fodhcpd.git router: fix dns search list option Fix regression issue introduced in commit 0523bdd as empty DNS search list option was sent making the RA message invalid Signed-off-by: Hans Dedecker --- diff --git a/src/router.c b/src/router.c index a897d5b..3a6b121 100644 --- a/src/router.c +++ b/src/router.c @@ -587,7 +587,7 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr /* DNS options */ if (iface->ra_dns) { struct in6_addr dns_pref, *dns_addr = NULL; - size_t dns_cnt = 0, search_padded = 0, search_len = iface->search_len; + size_t dns_cnt = 0, search_len = iface->search_len; uint8_t *search_domain = iface->search; /* DNS Recursive DNS */ @@ -622,18 +622,16 @@ static int send_router_advert(struct interface *iface, const struct in6_addr *fr } } - if (search_len > 0) - search_padded = ((search_len + 7) & (~7)) + 8; - - search_sz = sizeof(*search) + search_padded; + if (search_len > 0) { + size_t search_padded = ((search_len + 7) & (~7)) + 8; - search = alloca(search_sz); - memset(search, 0, search_sz); - search->type = ND_OPT_DNS_SEARCH; - search->len = search_len ? ((sizeof(*search) + search_padded) / 8) : 0; - search->lifetime = htonl(lifetime); + search_sz = sizeof(*search) + search_padded; - if (search_len > 0) { + search = alloca(search_sz); + memset(search, 0, search_sz); + search->type = ND_OPT_DNS_SEARCH; + search->len = search_len ? ((sizeof(*search) + search_padded) / 8) : 0; + search->lifetime = htonl(lifetime); memcpy(search->name, search_domain, search_len); memset(&search->name[search_len], 0, search_padded - search_len); }