From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from huawei.com (szxga05-in.huawei.com [45.249.212.191]) by dpdk.org (Postfix) with ESMTP id 1369C1B3B4 for ; Thu, 29 Nov 2018 06:32:44 +0100 (CET) Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 712A5FC044A1E; Thu, 29 Nov 2018 13:32:41 +0800 (CST) Received: from localhost (10.177.20.223) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.408.0; Thu, 29 Nov 2018 13:32:41 +0800 From: Haifeng Lin To: CC: Date: Thu, 29 Nov 2018 13:32:41 +0800 Message-ID: <1543469561-8864-1-git-send-email-haifeng.lin@huawei.com> X-Mailer: git-send-email 1.8.5.2.msysgit.0 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.177.20.223] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH] net/bonding: fix double fetch for active_slave_count X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Nov 2018 05:32:45 -0000 1. when memcpy slaves the internals->active_slave_count 1 2. return internals->active_slave_count is 2 3. the slaves[1] would be a random invalid value Signed-off-by: Haifeng Lin --- drivers/net/bonding/rte_eth_bond_api.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/bonding/rte_eth_bond_api.c b/drivers/net/bonding/rte_eth_bond_api.c index 21bcd50..ed7b02e 100644 --- a/drivers/net/bonding/rte_eth_bond_api.c +++ b/drivers/net/bonding/rte_eth_bond_api.c @@ -815,6 +815,7 @@ uint16_t len) { struct bond_dev_private *internals; + uint16_t active_slave_count; if (valid_bonded_port_id(bonded_port_id) != 0) return -1; @@ -824,13 +825,14 @@ internals = rte_eth_devices[bonded_port_id].data->dev_private; - if (internals->active_slave_count > len) + active_slave_count = internals->active_slave_count; + if (active_slave_count > len) return -1; memcpy(slaves, internals->active_slaves, - internals->active_slave_count * sizeof(internals->active_slaves[0])); + active_slave_count * sizeof(internals->active_slaves[0])); - return internals->active_slave_count; + return active_slave_count; } int -- 1.8.5.2.msysgit.0