From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id 713B74C90 for ; Tue, 27 Feb 2018 01:15:05 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Feb 2018 16:15:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,398,1515484800"; d="scan'208";a="29962406" Received: from irsmsx107.ger.corp.intel.com ([163.33.3.99]) by FMSMGA003.fm.intel.com with ESMTP; 26 Feb 2018 16:15:03 -0800 Received: from irsmsx156.ger.corp.intel.com (10.108.20.68) by IRSMSX107.ger.corp.intel.com (163.33.3.99) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 27 Feb 2018 00:15:01 +0000 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.221]) by IRSMSX156.ger.corp.intel.com ([169.254.3.24]) with mapi id 14.03.0319.002; Tue, 27 Feb 2018 00:15:01 +0000 From: "Ananyev, Konstantin" To: "Awal, Mohammad Abdul" , "thomas@monjalon.net" CC: "rkerur@gmail.com" , "dev@dpdk.org" , "Awal, Mohammad Abdul" Thread-Topic: [dpdk-dev] [PATCH] ether: fix invalid string length in ethdev name comparison Thread-Index: AQHTr1ijeN7eTvcGqEK2+wlaTKXRLaO3YQ9A Date: Tue, 27 Feb 2018 00:15:01 +0000 Message-ID: <2601191342CEEE43887BDE71AB97725890578299@irsmsx105.ger.corp.intel.com> References: <1519687296-2872-1-git-send-email-mohammad.abdul.awal@intel.com> In-Reply-To: <1519687296-2872-1-git-send-email-mohammad.abdul.awal@intel.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiOTM5MzIzYWEtOTczZS00Mzk0LTk2ODItMmYzMjlmMzQzZmZmIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6IkFIa2t6Wml1cENWUDdMTXZxeE9NNkt4T01NRXBUam9GeXh4TFRITjh3SzQ9In0= x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [163.33.239.180] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [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: , X-List-Received-Date: Tue, 27 Feb 2018 00:15:06 -0000 > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Mohammad Abdul Awal > Sent: Monday, February 26, 2018 11:22 PM > To: thomas@monjalon.net > Cc: rkerur@gmail.com; dev@dpdk.org; Awal, Mohammad Abdul > Subject: [dpdk-dev] [PATCH] ether: fix invalid string length in ethdev na= me comparison >=20 > 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 larg= er > string. >=20 > Fixes: 9c5b8d8b9fe ("ethdev: clean port id retrieval when attaching") >=20 > Signed-off-by: Mohammad Abdul Awal > --- > lib/librte_ether/rte_ethdev.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) >=20 > 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; >=20 > if (name =3D=3D NULL) { > RTE_PMD_DEBUG_TRACE("Null pointer is specified\n"); > return -EINVAL; > } >=20 > + len1 =3D strlen(name); > for (pid =3D 0; pid < RTE_MAX_ETHPORTS; pid++) { > + len2 =3D strlen(rte_eth_dev_shared_data->data[pid].name); > + len =3D len1 > len2 ? len1 : len2; > if (rte_eth_devices[pid].state !=3D RTE_ETH_DEV_UNUSED && > !strncmp(name, rte_eth_dev_shared_data->data[pid].name, > - strlen(name))) { > + len)) { Why just not simply use strcmp()? :) > *port_id =3D pid; > return 0; > } > -- > 2.7.4