diff --git a/lib/env_dpdk/memory.c b/lib/env_dpdk/memory.c index 8bf2f9817..db0ce9216 100644 --- a/lib/env_dpdk/memory.c +++ b/lib/env_dpdk/memory.c @@ -360,6 +360,10 @@ spdk_mem_map_get_map_1gb(struct spdk_mem_map *map, uint64_t vfn_2mb) uint64_t idx_256tb = MAP_256TB_IDX(vfn_2mb); size_t i; + if (spdk_unlikely(idx_256tb >= SPDK_COUNTOF(map->map_256tb.map))) { + return NULL; + } + map_1gb = map->map_256tb.map[idx_256tb]; if (!map_1gb) { diff --git a/test/env/memory/memory_ut.c b/test/env/memory/memory_ut.c index 2ae12c3c7..d1cf58eec 100644 --- a/test/env/memory/memory_ut.c +++ b/test/env/memory/memory_ut.c @@ -193,6 +193,10 @@ test_mem_map_translation(void) rc = spdk_mem_map_set_translation(map, 0x1000000000000ULL, VALUE_2MB, 0x5678); CU_ASSERT(rc == -EINVAL); + /* Attempt to set translation starting at a valid address but exceeding the valid range */ + rc = spdk_mem_map_set_translation(map, 0xffffffe00000ULL, VALUE_2MB * 2, 0x123123); + CU_ASSERT(rc != 0); + spdk_mem_map_free(&map); CU_ASSERT(map == NULL); }