[dpdk-dev] [PATCH 2/9] bus: verify bus name on registration

Gaetan Rivet gaetan.rivet at 6wind.com
Wed May 24 17:12:34 CEST 2017


Verify that a bus name is legal.

Signed-off-by: Gaetan Rivet <gaetan.rivet at 6wind.com>
---
 lib/librte_eal/common/eal_common_bus.c | 13 +++++++++++++
 lib/librte_eal/common/eal_private.h    | 16 ++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index b41ea86..8ef859a 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -47,6 +47,8 @@ rte_bus_register(struct rte_bus *bus)
 {
 	RTE_VERIFY(bus);
 	RTE_VERIFY(bus->name && strlen(bus->name));
+	/* Its whole name should be comprised only of valid characters */
+	RTE_VERIFY(rte_bus_name_valid(bus->name) == strlen(bus->name));
 	/* A bus should mandatorily have the scan implemented */
 	RTE_VERIFY(bus->scan);
 	RTE_VERIFY(bus->probe);
@@ -210,3 +212,14 @@ rte_bus_find_device(const struct rte_device *start,
 
 	return dev;
 }
+
+/* Validate a bus name. */
+size_t
+rte_bus_name_valid(const char *name)
+{
+	size_t i = 0;
+
+	while (isalnum(name[i]) || name[i] == '_')
+		i++;
+	return i;
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 6cacce0..6d2206a 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -338,4 +338,20 @@ int rte_eal_hugepage_attach(void);
  */
 bool rte_eal_using_phys_addrs(void);
 
+/*
+ * Validate a bus name.
+ *
+ * Counts the number of valid characters in a given name,
+ * starting from the beginning.
+ * A legal bus name is defined by the pattern:
+ *   [:alnum:_]+
+ *
+ * @param name
+ *	bus name
+ *
+ * @return
+ *	number of valid characters in name.
+ */
+size_t rte_bus_name_valid(const char *name);
+
 #endif /* _EAL_PRIVATE_H_ */
-- 
2.1.4



More information about the dev mailing list