router: fix dns search list option
authorHans Dedecker <dedeckeh@gmail.com>
Fri, 19 Apr 2019 11:16:58 +0000 (13:16 +0200)
committerHans Dedecker <dedeckeh@gmail.com>
Fri, 19 Apr 2019 17:17:38 +0000 (19:17 +0200)
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 <dedeckeh@gmail.com>
src/router.c

index a897d5ba7da4bb0a3935bc8ac6f628c4c70e30e0..3a6b12154ae4af1e818452696b2321a1ba553e0a 100644 (file)
@@ -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);
                }