router: fix possible segfault in send_router_advert()
authorHans Dedecker <dedeckeh@gmail.com>
Mon, 4 Jun 2018 20:07:13 +0000 (22:07 +0200)
committerHans Dedecker <dedeckeh@gmail.com>
Mon, 4 Jun 2018 20:07:13 +0000 (22:07 +0200)
Detected by Coverity in CID1412349

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
src/router.c

index 777cbc058c396ea52af023344b3f76f4afd9eb78..8e3013c1fb6b41f7ea5c8ca295b779d251d89a9f 100644 (file)
@@ -569,9 +569,11 @@ static uint64_t send_router_advert(struct interface *iface, const struct in6_add
        search->len = search_len ? ((sizeof(*search) + search_padded) / 8) : 0;
        search->pad = 0;
        search->pad2 = 0;
-       memcpy(search->name, search_domain, search_len);
-       memset(&search->name[search_len], 0, search_padded - search_len);
 
+       if (search_len > 0) {
+               memcpy(search->name, search_domain, search_len);
+               memset(&search->name[search_len], 0, search_padded - search_len);
+       }
 
        size_t routes_cnt = 0;
        struct {