From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Zhang, Qi Z" Subject: Re: [PATCH] ethdev: check for invalid device name Date: Wed, 13 Mar 2019 12:52:50 +0000 Message-ID: <039ED4275CED7440929022BC67E706115334BE52@SHSMSX103.ccr.corp.intel.com> References: <20190311181544.15646-1-stephen@networkplumber.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable To: Stephen Hemminger , "dev@dpdk.org" Return-path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 569FF3572 for ; Wed, 13 Mar 2019 13:52:54 +0100 (CET) In-Reply-To: <20190311181544.15646-1-stephen@networkplumber.org> Content-Language: en-US List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" HI > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Stephen Hemminger > Sent: Tuesday, March 12, 2019 2:16 AM > To: dev@dpdk.org > Cc: Stephen Hemminger > Subject: [dpdk-dev] [PATCH] ethdev: check for invalid device name >=20 > Do not allow creating a ethernet device with a name over the allowed maxi= mum > (or zero length). This is safer than silently truncating which is what ha= ppens now. >=20 > Signed-off-by: Stephen Hemminger > Acked-by: Andrew Rybchenko > --- > v1 - previously sent as RFC >=20 > lib/librte_ethdev/rte_ethdev.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) >=20 > diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethde= v.c > index 85c1794968dd..0b81980ff71c 100644 > --- a/lib/librte_ethdev/rte_ethdev.c > +++ b/lib/librte_ethdev/rte_ethdev.c > @@ -439,6 +439,16 @@ rte_eth_dev_allocate(const char *name) > uint16_t port_id; > struct rte_eth_dev *eth_dev =3D NULL; >=20 > + if (*name) { Is above check same as "strlen(name) =3D=3D 0"? > + RTE_ETHDEV_LOG(ERR, "Zero length Ethernet device name\n"); > + return NULL; > + } > + > + if (strnlen(name, RTE_ETH_NAME_MAX_LEN) >=3D > RTE_ETH_NAME_MAX_LEN) { > + RTE_ETHDEV_LOG(ERR, "Ethernet device name is too long\n"); > + return NULL; > + } > + > rte_eth_dev_shared_data_prepare(); >=20 > /* Synchronize port creation between primary and secondary threads. */ > -- > 2.17.1