Don't segfault with an unset ula_prefix
authorSteven Barth <steven@midlink.org>
Tue, 22 Jan 2013 15:42:40 +0000 (16:42 +0100)
committerSteven Barth <steven@midlink.org>
Tue, 22 Jan 2013 15:42:40 +0000 (16:42 +0100)
interface-ip.c

index 892631d4e25ec3b82457dac94b7be25b1f0e2e31..ea4c3ddbf989b31c22481caee15b8e2f77c8ec6a 100644 (file)
@@ -634,12 +634,18 @@ void
 interface_ip_set_ula_prefix(const char *prefix)
 {
        char buf[INET6_ADDRSTRLEN + 4] = {0}, *saveptr;
-       strncpy(buf, prefix, sizeof(buf) - 1);
+       if (prefix)
+               strncpy(buf, prefix, sizeof(buf) - 1);
        char *prefixaddr = strtok_r(buf, "/", &saveptr);
 
        struct in6_addr addr;
-       if (!prefixaddr || inet_pton(AF_INET6, prefixaddr, &addr) < 1)
+       if (!prefixaddr || inet_pton(AF_INET6, prefixaddr, &addr) < 1) {
+               if (ula_prefix) {
+                       interface_update_prefix(NULL, NULL, &ula_prefix->node);
+                       ula_prefix = NULL;
+               }
                return;
+       }
 
        int length;
        char *prefixlen = strtok_r(NULL, ",", &saveptr);