]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Don't violate memory when we learn new IPv4LL addresses.
authorRoy Marples <roy@marples.name>
Mon, 5 Sep 2016 20:08:46 +0000 (20:08 +0000)
committerRoy Marples <roy@marples.name>
Mon, 5 Sep 2016 20:08:46 +0000 (20:08 +0000)
ipv4.c

diff --git a/ipv4.c b/ipv4.c
index dbe04899cf2ebaf06f8badad27f9834283765107..84504d40e1a73c9ffc1d03f6acc479f7c21bf637 100644 (file)
--- a/ipv4.c
+++ b/ipv4.c
@@ -37,6 +37,7 @@
 #include <assert.h>
 #include <ctype.h>
 #include <errno.h>
+#include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -1263,6 +1264,7 @@ ipv4_handleifa(struct dhcpcd_ctx *ctx,
        struct ipv4_state *state;
        struct ipv4_addr *ia;
        int flags;
+       bool ia_is_new;
 
        if (ifs == NULL)
                ifs = ctx->ifaces;
@@ -1287,14 +1289,18 @@ ipv4_handleifa(struct dhcpcd_ctx *ctx,
                        }
                        ia->iface = ifp;
                        ia->addr = *addr;
+                       ia->mask = *mask;
+                       ia_is_new = true;
 #ifdef ALIAS_ADDR
                        strlcpy(ia->alias, ifname, sizeof(ia->alias));
 #endif
                        TAILQ_INSERT_TAIL(&state->addrs, ia, next);
-               }
+               } else
+                       ia_is_new = false;
                /* Mask could have changed */
-               if (mask->s_addr != INADDR_ANY &&
-                   mask->s_addr != ia->mask.s_addr)
+               if (ia_is_new ||
+                   (mask->s_addr != INADDR_ANY &&
+                   mask->s_addr != ia->mask.s_addr))
                {
                        ia->mask = *mask;
                        snprintf(ia->saddr, sizeof(ia->saddr), "%s/%d",