From: Roy Marples Date: Tue, 30 Jul 2019 10:04:24 +0000 (+0100) Subject: routes: Fix a NULL dereference error for global static routes X-Git-Tag: v8.0.2^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aaa0ed852d6f1e9e17b0cf7ce985bd5cb130c999;p=thirdparty%2Fdhcpcd.git routes: Fix a NULL dereference error for global static routes No idea why you would want them, but just in case ..... --- diff --git a/src/dhcpcd.c b/src/dhcpcd.c index ac498a62..5b64abf4 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -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) { diff --git a/src/if-options.c b/src/if-options.c index 04e519ee..19337e04 100644 --- a/src/if-options.c +++ b/src/if-options.c @@ -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);