From: Li Qiang Date: Thu, 3 Jan 2019 13:12:51 +0000 (-0800) Subject: hw: rdma: fix an off-by-one issue X-Git-Tag: v4.0.0-rc0~153^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a5fe209d71f311afb0035ce39e9472f9b31445e9;p=thirdparty%2Fqemu.git hw: rdma: fix an off-by-one issue In rdma_rm_get_backend_gid_index(), the 'sgid_idx' is used to index the array 'dev_res->port.gid_tbl' which size is MAX_PORT_GIDS. Current the 'sgid_idx' may be MAX_PORT_GIDS thus cause an off-by-one issue. Spotted by Coverity: CID 1398594 Signed-off-by: Li Qiang Message-Id: <20190103131251.49271-1-liq3ea@163.com> Signed-off-by: Marcel Apfelbaum --- diff --git a/hw/rdma/rdma_rm.c b/hw/rdma/rdma_rm.c index 8bf241e91f3..268ff633a48 100644 --- a/hw/rdma/rdma_rm.c +++ b/hw/rdma/rdma_rm.c @@ -579,7 +579,7 @@ int rdma_rm_del_gid(RdmaDeviceResources *dev_res, RdmaBackendDev *backend_dev, int rdma_rm_get_backend_gid_index(RdmaDeviceResources *dev_res, RdmaBackendDev *backend_dev, int sgid_idx) { - if (unlikely(sgid_idx < 0 || sgid_idx > MAX_PORT_GIDS)) { + if (unlikely(sgid_idx < 0 || sgid_idx >= MAX_PORT_GIDS)) { pr_dbg("Got invalid sgid_idx %d\n", sgid_idx); return -EINVAL; }