Check that lpm name size is within limits and add checks
for truncation.
Signed-off-by: Stephen Hemminger <[email protected]>
---
lib/lpm/rte_lpm.c | 16 ++++++++++++----
lib/lpm/rte_lpm.h | 1 +
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/lib/lpm/rte_lpm.c b/lib/lpm/rte_lpm.c
index 6dab86a05e..9c20eb731c 100644
--- a/lib/lpm/rte_lpm.c
+++ b/lib/lpm/rte_lpm.c
@@ -152,7 +152,7 @@ struct rte_lpm *
rte_lpm_create(const char *name, int socket_id,
const struct rte_lpm_config *config)
{
- char mem_name[RTE_LPM_NAMESIZE];
+ char mem_name[RTE_LPM_NAMESIZE + sizeof("LPM_")];
struct __rte_lpm *i_lpm;
struct rte_lpm *lpm = NULL;
struct rte_tailq_entry *te;
@@ -170,6 +170,11 @@ rte_lpm_create(const char *name, int socket_id,
return NULL;
}
+ if (strlen(name) >= RTE_LPM_NAMESIZE) {
+ rte_errno = ENAMETOOLONG;
+ return NULL;
+ }
+
snprintf(mem_name, sizeof(mem_name), "LPM_%s", name);
rte_mcfg_tailq_write_lock();
@@ -327,8 +332,10 @@ rte_lpm_rcu_qsbr_add(struct rte_lpm *lpm, struct
rte_lpm_rcu_config *cfg)
/* No other things to do. */
} else if (cfg->mode == RTE_LPM_QSBR_MODE_DQ) {
/* Init QSBR defer queue. */
- snprintf(rcu_dq_name, sizeof(rcu_dq_name),
- "LPM_RCU_%s", i_lpm->name);
+ if (snprintf(rcu_dq_name, sizeof(rcu_dq_name),
+ "LPM_RCU_%s", i_lpm->name) >=
(int)sizeof(rcu_dq_name))
+ LPM_LOG(NOTICE, "LPM rcu defer queue name truncated");
+
params.name = rcu_dq_name;
params.size = cfg->dq_size;
if (params.size == 0)
@@ -343,7 +350,8 @@ rte_lpm_rcu_qsbr_add(struct rte_lpm *lpm, struct
rte_lpm_rcu_config *cfg)
params.v = cfg->v;
i_lpm->dq = rte_rcu_qsbr_dq_create(¶ms);
if (i_lpm->dq == NULL) {
- LPM_LOG(ERR, "LPM defer queue creation failed");
+ LPM_LOG(ERR, "LPM defer queue creation failed: %s",
+ rte_strerror(rte_errno));
return 1;
}
} else {
diff --git a/lib/lpm/rte_lpm.h b/lib/lpm/rte_lpm.h
index edfe77b458..38a061513f 100644
--- a/lib/lpm/rte_lpm.h
+++ b/lib/lpm/rte_lpm.h
@@ -180,6 +180,7 @@ rte_lpm_free(struct rte_lpm *lpm);
* - ENOSPC - the maximum number of memzones has already been allocated
* - EEXIST - a memzone with the same name already exists
* - ENOMEM - no appropriate memory area found in which to create memzone
+ * - ENAMETOOLONG - LPM object name greater than RTE_LPM_NAMESIZE
*/
struct rte_lpm *
rte_lpm_create(const char *name, int socket_id,
--
2.51.0