From patchwork Mon Feb 26 23:21:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mohammad Abdul Awal X-Patchwork-Id: 35433 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 21F9A49E0; Tue, 27 Feb 2018 00:21:55 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 2D3CE2BDF for ; Tue, 27 Feb 2018 00:21:53 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Feb 2018 15:21:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,398,1515484800"; d="scan'208";a="20404201" Received: from awal-z170x.ir.intel.com ([163.33.210.59]) by fmsmga007.fm.intel.com with ESMTP; 26 Feb 2018 15:21:51 -0800 From: Mohammad Abdul Awal To: thomas@monjalon.net Cc: rkerur@gmail.com, dev@dpdk.org, Mohammad Abdul Awal Date: Mon, 26 Feb 2018 23:21:36 +0000 Message-Id: <1519687296-2872-1-git-send-email-mohammad.abdul.awal@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH] ether: fix invalid string length in ethdev name comparison 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The current code compares two strings upto the length of 1st string (searched name). If the 1st string is prefix of 2nd string (existing name), the string comparison returns the port_id of earliest prefix matches. This patch fixes the bug by comparing the strings upto the length of larger string. Fixes: 9c5b8d8b9fe ("ethdev: clean port id retrieval when attaching") Signed-off-by: Mohammad Abdul Awal --- lib/librte_ether/rte_ethdev.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 0590f0c..8e8097b 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -563,17 +563,20 @@ rte_eth_dev_get_name_by_port(uint16_t port_id, char *name) int rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id) { - uint32_t pid; + uint32_t pid, len, len1, len2; if (name == NULL) { RTE_PMD_DEBUG_TRACE("Null pointer is specified\n"); return -EINVAL; } + len1 = strlen(name); for (pid = 0; pid < RTE_MAX_ETHPORTS; pid++) { + len2 = strlen(rte_eth_dev_shared_data->data[pid].name); + len = len1 > len2 ? len1 : len2; if (rte_eth_devices[pid].state != RTE_ETH_DEV_UNUSED && !strncmp(name, rte_eth_dev_shared_data->data[pid].name, - strlen(name))) { + len)) { *port_id = pid; return 0; }