From: Roy Marples Date: Tue, 9 May 2017 11:29:40 +0000 (+0100) Subject: Don't crash when --static routers= is given on the command line. X-Git-Tag: v7.0.0-rc1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2065e8ebca903aabd075e6ee0da8d9f372f54756;p=thirdparty%2Fdhcpcd.git Don't crash when --static routers= is given on the command line. T116 will make it work for the control socket. --- diff --git a/src/if-options.c b/src/if-options.c index 0f5be071..3edc0dbe 100644 --- a/src/if-options.c +++ b/src/if-options.c @@ -1066,8 +1066,14 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, strncmp(arg, "ms_classless_static_routes=", strlen("ms_classless_static_routes=")) == 0) { + struct interface *ifp; struct in_addr addr3; + ifp = if_find(ctx->ifaces, ifname); + if (ifp == NULL) { + logerrx("static routes require an interface"); + return -1; + } fp = np = strwhite(p); if (np == NULL) { logerrx("all routes need a gateway"); @@ -1081,7 +1087,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, *fp = ' '; return -1; } - if ((rt = rt_new(if_find(ctx->ifaces, ifname))) == NULL) { + if ((rt = rt_new(ifp)) == NULL) { *fp = ' '; return -1; } @@ -1091,9 +1097,16 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, TAILQ_INSERT_TAIL(&ifo->routes, rt, rt_next); *fp = ' '; } else if (strncmp(arg, "routers=", strlen("routers=")) == 0) { + struct interface *ifp; + + ifp = if_find(ctx->ifaces, ifname); + if (ifp == NULL) { + logerrx("static routes require an interface"); + return -1; + } if (parse_addr(&addr, NULL, p) == -1) return -1; - if ((rt = rt_new(if_find(ctx->ifaces, ifname))) == NULL) + if ((rt = rt_new(ifp)) == NULL) return -1; addr2.s_addr = INADDR_ANY; sa_in_init(&rt->rt_dest, &addr2);