From: Stephen Hemminger Date: Thu, 14 Mar 2019 16:20:47 +0000 (-0700) Subject: ethdev: check for invalid device name X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=0366137722a0826325c3da324ef80c7adffac722;p=dpdk.git ethdev: check for invalid device name Do not allow creating an 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 Acked-by: Qi Zhang Acked-by: Ali Alnubani --- diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 3f2253643e..12b66b68c6 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -438,6 +438,18 @@ rte_eth_dev_allocate(const char *name) { uint16_t port_id; struct rte_eth_dev *eth_dev = NULL; + size_t name_len; + + name_len = strnlen(name, RTE_ETH_NAME_MAX_LEN); + if (name_len == 0) { + RTE_ETHDEV_LOG(ERR, "Zero length Ethernet device name\n"); + return NULL; + } + + if (name_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();