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 <stephen@networkplumber.org>
Acked-by: Andrew Rybchenko <arybchenko@solarflare.com>
Acked-by: Qi Zhang <qi.z.zhang@intel.com>
Acked-by: Ali Alnubani <alialnu@mellanox.com>
This commit is contained in:
Stephen Hemminger 2019-03-14 09:20:47 -07:00 committed by Ferruh Yigit
parent cf6a73fc3f
commit 0366137722

View File

@ -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();