Thread (123 messages) 123 messages, 7 authors, 2017-07-08
STALE3306d
Revisions (8)
  1. v1 [diff vs current]
  2. v2 [diff vs current]
  3. v3 [diff vs current]
  4. v4 current
  5. v5 [diff vs current]
  6. v6 [diff vs current]
  7. v7 [diff vs current]
  8. v8 [diff vs current]

[PATCH v4 2/9] bus: verify bus name on registration

From: Gaetan Rivet <hidden>
Date: 2017-06-07 23:56:24
Subsystem: library code, the rest · Maintainers: Andrew Morton, Linus Torvalds

Verify that a bus name is legal.

Signed-off-by: Gaetan Rivet <redacted>
---
 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 381a0b6..d9d8f62 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);
@@ -207,3 +209,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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help