]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
dhcpcd: Don't leak memory when routing socket overflows
authorRoy Marples <roy@marples.name>
Tue, 23 Jul 2019 13:53:01 +0000 (14:53 +0100)
committerRoy Marples <roy@marples.name>
Tue, 23 Jul 2019 13:53:01 +0000 (14:53 +0100)
src/dhcpcd.c

index a142ef6ee007a1a51e7a4e7ea5b914456493d337..3584d2234c53fc782bfdf253fa5c95c3121c4200 100644 (file)
@@ -1135,6 +1135,10 @@ dhcpcd_linkoverflow(struct dhcpcd_ctx *ctx)
 
        /* Work out the current interfaces. */
        ifaces = if_discover(ctx, &ifaddrs, ctx->ifc, ctx->ifv);
+       if (ifaces == NULL) {
+               logerr(__func__);
+               return;
+       }
 
        /* Punt departed interfaces */
        TAILQ_FOREACH_SAFE(ifp, ctx->ifaces, next, ifn) {
@@ -1144,21 +1148,23 @@ dhcpcd_linkoverflow(struct dhcpcd_ctx *ctx)
        }
 
        /* Add new interfaces */
-       TAILQ_FOREACH_SAFE(ifp, ifaces, next, ifn) {
+       while ((ifp = TAILQ_FIRST(ifaces)) != NULL ) {
+               TAILQ_REMOVE(ifaces, ifp, next);
                ifp1 = if_find(ctx->ifaces, ifp->name);
                if (ifp1 != NULL) {
                        /* If the interface already exists,
                         * check carrier state. */
                        eloop_timeout_add_sec(ctx->eloop, 0,
                            dhcpcd_checkcarrier, ifp1);
+                       if_free(ifp);
                        continue;
                }
-               TAILQ_REMOVE(ifaces, ifp, next);
                TAILQ_INSERT_TAIL(ctx->ifaces, ifp, next);
                if (ifp->active)
                        eloop_timeout_add_sec(ctx->eloop, 0,
                            dhcpcd_prestartinterface, ifp);
        }
+       free(ifaces);
 
        /* Update address state. */
        if_markaddrsstale(ctx->ifaces);