]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
routes: Fix a NULL dereference error for global static routes v8.0.2
authorRoy Marples <roy@marples.name>
Tue, 30 Jul 2019 10:04:24 +0000 (11:04 +0100)
committerRoy Marples <roy@marples.name>
Tue, 30 Jul 2019 10:04:24 +0000 (11:04 +0100)
No idea why you would want them, but just in case .....

src/dhcpcd.c
src/if-options.c

index ac498a621880b7e7522c1bd1690fc6631db4704d..5b64abf49aa3cf0bad8e351c32618464b62887a2 100644 (file)
@@ -2125,13 +2125,13 @@ exit1:
                }
                free(ctx.ifaces);
        }
+       free_options(&ctx, ifo);
 #ifdef HAVE_OPEN_MEMSTREAM
        if (ctx.script_fp)
                fclose(ctx.script_fp);
 #endif
        free(ctx.script_buf);
        free(ctx.script_env);
-       free_options(&ctx, ifo);
        rt_dispose(&ctx);
        free(ctx.duid);
        if (ctx.link_fd != -1) {
index 04e519eee1c437133e94e8ae824b822c456e6fc2..19337e042366eb789ee4b2ce467b52a80757302f 100644 (file)
@@ -2612,6 +2612,7 @@ free_options(struct dhcpcd_ctx *ctx, struct if_options *ifo)
 {
        size_t i;
 #ifdef RT_FREE_ROUTE_TABLE
+       struct interface *ifp;
        struct rt *rt;
 #endif
        struct dhcp_opt *opt;
@@ -2640,9 +2641,12 @@ free_options(struct dhcpcd_ctx *ctx, struct if_options *ifo)
        /* Stupidly, we don't know the interface when creating the options.
         * As such, make sure each route has one so they can goto the
         * free list. */
-       RB_TREE_FOREACH(rt, &ifo->routes) {
-               if (rt->rt_ifp == NULL)
-                       rt->rt_ifp = TAILQ_FIRST(ctx->ifaces);
+       ifp = ctx->ifaces != NULL ? TAILQ_FIRST(ctx->ifaces) : NULL;
+       if (ifp != NULL) {
+               RB_TREE_FOREACH(rt, &ifo->routes) {
+                       if (rt->rt_ifp == NULL)
+                               rt->rt_ifp = ifp;
+               }
        }
 #endif
        rt_headclear0(ctx, &ifo->routes, AF_UNSPEC);