Skip to contentSkip to conversation

ethdev: check for invalid device name

PATCH Superseded Stephen Hemminger 1 participant 1 message Mar 14, 2019

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ethdev: check for invalid device name

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.

---
v2 - fix zero length name test

 lib/librte_ethdev/rte_ethdev.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
lib/librte_ethdev/rte_ethdev.c +12 -0
index 85c1794968dd..b19df3061d54 100644
@@ -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();
 
Signature · 1 line
2.17.1