nexthop: off by one in nexthop_mpath_select()
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 7 Jun 2019 15:31:07 +0000 (18:31 +0300)
committerDavid S. Miller <davem@davemloft.net>
Sun, 9 Jun 2019 20:37:25 +0000 (13:37 -0700)
The nhg->nh_entries[] array is allocated in nexthop_grp_alloc() and it
has nhg->num_nh elements so this check should be >= instead of >.

Fixes: 430a049190de ("nexthop: Add support for nexthop groups")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/nexthop.h

index aff7b2410057c9cbcc9184206be2c0fba9c13382..e019ed9b3dc3e76ede4e7081ffe7e9d5e54647b5 100644 (file)
@@ -160,7 +160,7 @@ struct nexthop *nexthop_mpath_select(const struct nexthop *nh, int nhsel)
        /* for_nexthops macros in fib_semantics.c grabs a pointer to
         * the nexthop before checking nhsel
         */
-       if (nhsel > nhg->num_nh)
+       if (nhsel >= nhg->num_nh)
                return NULL;
 
        return nhg->nh_entries[nhsel].nh;