]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
iproute: Abort if nexthop cannot be parsed
authorJakub Sitnicki <jkbs@redhat.com>
Wed, 11 Apr 2018 09:43:11 +0000 (11:43 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 16 Apr 2018 23:58:38 +0000 (16:58 -0700)
Attempt to add a multipath route where a nexthop definition refers to a
non-existent device causes 'ip' to crash and burn due to stack buffer
overflow:

  # ip -6 route add fd00::1/64 nexthop dev fake1
  Cannot find device "fake1"
  Cannot find device "fake1"
  Cannot find device "fake1"
  ...
  Segmentation fault (core dumped)

Don't ignore errors from the helper routine that parses the nexthop
definition, and abort immediately if parsing fails.

Signed-off-by: Jakub Sitnicki <jkbs@redhat.com>
ip/iproute.c

index 1d8fd8154f0e2cd1d1244a46bb6167146c418b79..44351bc51b4bd7dd3d08f6357a720288e0ca4bc3 100644 (file)
@@ -1038,7 +1038,10 @@ static int parse_nexthops(struct nlmsghdr *n, struct rtmsg *r,
                memset(rtnh, 0, sizeof(*rtnh));
                rtnh->rtnh_len = sizeof(*rtnh);
                rta->rta_len += rtnh->rtnh_len;
-               parse_one_nh(n, r, rta, rtnh, &argc, &argv);
+               if (parse_one_nh(n, r, rta, rtnh, &argc, &argv)) {
+                       fprintf(stderr, "Error: cannot parse nexthop\n");
+                       exit(-1);
+               }
                rtnh = RTNH_NEXT(rtnh);
        }