mem: avoid memzone/mempool/ring name truncation
[dpdk.git] / lib / librte_eal / common / eal_common_memzone.c
index a8f804c..452679e 100644 (file)
@@ -126,6 +126,7 @@ static const struct rte_memzone *
 memzone_reserve_aligned_thread_unsafe(const char *name, size_t len,
                int socket_id, unsigned flags, unsigned align, unsigned bound)
 {
+       struct rte_memzone *mz;
        struct rte_mem_config *mcfg;
        size_t requested_len;
        int socket, i;
@@ -148,6 +149,13 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len,
                return NULL;
        }
 
+       if (strlen(name) >= sizeof(mz->name) - 1) {
+               RTE_LOG(DEBUG, EAL, "%s(): memzone <%s>: name too long\n",
+                       __func__, name);
+               rte_errno = EEXIST;
+               return NULL;
+       }
+
        /* if alignment is not a power of two */
        if (align && !rte_is_power_of_2(align)) {
                RTE_LOG(ERR, EAL, "%s(): Invalid alignment: %u\n", __func__,
@@ -223,7 +231,7 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len,
        const struct malloc_elem *elem = malloc_elem_from_data(mz_addr);
 
        /* fill the zone in config */
-       struct rte_memzone *mz = get_next_free_memzone();
+       mz = get_next_free_memzone();
 
        if (mz == NULL) {
                RTE_LOG(ERR, EAL, "%s(): Cannot find free memzone but there is room "