summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2019-07-30 11:04:24 +0100
committerRoy Marples <roy@marples.name>2019-07-30 11:04:24 +0100
commitaaa0ed852d6f1e9e17b0cf7ce985bd5cb130c999 (patch)
tree14b7f68a14f055ffc804fe191c30df5a6bf929e4
parentfb244ec0206938e736c57bd55be27349c8de81b7 (diff)
downloaddhcpcd-aaa0ed852d6f1e9e17b0cf7ce985bd5cb130c999.tar.xz
routes: Fix a NULL dereference error for global static routesdhcpcd-8.0.2
No idea why you would want them, but just in case .....
-rw-r--r--src/dhcpcd.c2
-rw-r--r--src/if-options.c10
2 files changed, 8 insertions, 4 deletions
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);