From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: [PATCH] ethdev: check for invalid device name Date: Mon, 11 Mar 2019 11:15:44 -0700 Message-ID: <20190311181544.15646-1-stephen@networkplumber.org> Cc: Stephen Hemminger To: dev@dpdk.org Return-path: Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by dpdk.org (Postfix) with ESMTP id 74B2A49E0 for ; Mon, 11 Mar 2019 19:15:48 +0100 (CET) Received: by mail-pg1-f193.google.com with SMTP id a22so4633581pgg.13 for ; Mon, 11 Mar 2019 11:15:48 -0700 (PDT) List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Do not allow creating a ethernet device with a name over the allowed maximum (or zero length). This is safer than silently truncating which is what happens now. Signed-off-by: Stephen Hemminger Acked-by: Andrew Rybchenko --- v1 - previously sent as RFC lib/librte_ethdev/rte_ethdev.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.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 = NULL; + if (*name) { + RTE_ETHDEV_LOG(ERR, "Zero length Ethernet device name\n"); + return NULL; + } + + if (strnlen(name, RTE_ETH_NAME_MAX_LEN) >= RTE_ETH_NAME_MAX_LEN) { + RTE_ETHDEV_LOG(ERR, "Ethernet device name is too long\n"); + return NULL; + } + rte_eth_dev_shared_data_prepare(); /* Synchronize port creation between primary and secondary threads. */ -- 2.17.1