Skip to contentSkip to conversation

putting null checks on ops_name

PATCH Superseded Muhammad Bilal 4 participants 5 messages Apr 6, 2020 – Apr 25, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 putting null checks on ops_name

Bugzilla ID: 353

---
 lib/librte_mbuf/rte_mbuf_pool_ops.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/librte_mbuf/rte_mbuf_pool_ops.c +4 -2
index 5722976fe..c3ddfc0bd 100644
@@ -13,7 +13,8 @@ int
 rte_mbuf_set_platform_mempool_ops(const char *ops_name)
 {
 	const struct rte_memzone *mz;
-
+	if (strlen(ops_name) == 0)
+		return -1;
 	if (strlen(ops_name) >= RTE_MEMPOOL_OPS_NAMESIZE)
 		return -ENAMETOOLONG;
 
@@ -50,7 +51,8 @@ int
 rte_mbuf_set_user_mempool_ops(const char *ops_name)
 {
 	const struct rte_memzone *mz;
-
+	if (strlen(ops_name) == 0)
+		return -1;
 	if (strlen(ops_name) >= RTE_MEMPOOL_OPS_NAMESIZE)
 		return -ENAMETOOLONG;
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 24 lines · On Mon, 6 Apr 2020 16:30:20 +0500 Muhammad Bilal <[email protected]> wrote:

Bugzilla ID: 353

---
 lib/librte_mbuf/rte_mbuf_pool_ops.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/librte_mbuf/rte_mbuf_pool_ops.c +2 -1
index 5722976fe..c3ddfc0bd 100644
@@ -13,7 +13,8 @@ int
 rte_mbuf_set_platform_mempool_ops(const char *ops_name)
 {
 	const struct rte_memzone *mz;
-
+	if (strlen(ops_name) == 0)
+		return -1;
 	if (strlen(ops_name) >= RTE_MEMPOOL_OPS_NAMESIZE)
 		return -ENAMETOOLONG;
 

lib/librte_mbuf/rte_mbuf_pool_ops.c int · line 58

Quoted 9 lines
lib/librte_mbuf/rte_mbuf_pool_ops.c +2 -1
@@ -50,7 +51,8 @@ int
 rte_mbuf_set_user_mempool_ops(const char *ops_name)
 {
 	const struct rte_memzone *mz;
-
+	if (strlen(ops_name) == 0)
+		return -1;
 	if (strlen(ops_name) >= RTE_MEMPOOL_OPS_NAMESIZE)
 		return -ENAMETOOLONG;
 

If you want to do it simpler and safer use strnlen. Also, don't mix -1 wit -errno returns.

	size_t len = strnlen(ops_name, RTE_MEMPOOL_OPS_NAMESIZE);

	if (len == 0)
		return -EINVAL;

	if (len == RTE_MEMPOOL_OPS_NAMESIZE)
		return -ENAMETOOLONG;
#2 lore raw

PATCH v2 1/1 putting null checks on ops_name

In reply to Muhammad Bilal

Bugzilla ID: 353

---
 lib/librte_mbuf/rte_mbuf_pool_ops.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
lib/librte_mbuf/rte_mbuf_pool_ops.c +8 -4
index 5722976fe..00186aa15 100644
@@ -13,8 +13,10 @@ int
 rte_mbuf_set_platform_mempool_ops(const char *ops_name)
 {
 	const struct rte_memzone *mz;
-
-	if (strlen(ops_name) >= RTE_MEMPOOL_OPS_NAMESIZE)
+	size_t len = strnlen(ops_name, RTE_MEMPOOL_OPS_NAMESIZE);
+	if (len == 0)
+		return -EINVAL;
+	if (len == RTE_MEMPOOL_OPS_NAMESIZE)
 		return -ENAMETOOLONG;
 
 	mz = rte_memzone_lookup("mbuf_platform_pool_ops");
@@ -50,8 +52,10 @@ int
 rte_mbuf_set_user_mempool_ops(const char *ops_name)
 {
 	const struct rte_memzone *mz;
-
-	if (strlen(ops_name) >= RTE_MEMPOOL_OPS_NAMESIZE)
+	size_t len = strnlen(ops_name, RTE_MEMPOOL_OPS_NAMESIZE);
+	if (len == 0)
+		return -EINVAL;
+	if (len == RTE_MEMPOOL_OPS_NAMESIZE)
 		return -ENAMETOOLONG;
 
 	mz = rte_memzone_lookup("mbuf_user_pool_ops");
Signature · 1 line
2.17.1
Acked-by Hemant Agrawal on v2 1/1
#4 lore raw
In reply to Muhammad Bilal

07/04/2020 09:56, Muhammad Bilal:

Quoted 5 lines

Bugzilla ID: 353

No need to Cc stable in my opinion, as there is no bug fixed.

Changing the name to:
mbuf: prevent setting mempool ops name empty

Applied with below minor change, thanks

The blank line below should remain:

Quoted 6 lines
lib/librte_mbuf/rte_mbuf_pool_ops.c +3 -2
 	const struct rte_memzone *mz;
-
-	if (strlen(ops_name) >= RTE_MEMPOOL_OPS_NAMESIZE)
+	size_t len = strnlen(ops_name, RTE_MEMPOOL_OPS_NAMESIZE);
+	if (len == 0)
+		return -EINVAL;