]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Don't crash when --static routers= is given on the command line.
authorRoy Marples <roy@marples.name>
Tue, 9 May 2017 11:29:40 +0000 (12:29 +0100)
committerRoy Marples <roy@marples.name>
Tue, 9 May 2017 11:29:40 +0000 (12:29 +0100)
T116 will make it work for the control socket.

src/if-options.c

index 0f5be07129a2d2786d19483107b35c93dfe803c3..3edc0dbe6bb132ccd3b9308bb4457da7a3f99c77 100644 (file)
@@ -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);