Value returned by rte_socket_id_by_idx() may be negative, which would result in negative array index access.
Coverity issue: 272600 Fixes: b666f17858a3 ("mem: read hugepage counts from node-specific sysfs path") Cc: anatoly.bura...@intel.com Signed-off-by: Anatoly Burakov <anatoly.bura...@intel.com> --- lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c index fb4b667..009f963 100644 --- a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c +++ b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c @@ -402,9 +402,16 @@ hugepage_info_init(void) /* we also don't want to do this for legacy init */ if (!internal_config.legacy_mem) for (i = 0; i < rte_socket_count(); i++) { - int socket = rte_socket_id_by_idx(i); - unsigned int num_pages = - get_num_hugepages_on_node( + int socket; + unsigned int num_pages; + + socket = rte_socket_id_by_idx(i); + if (socket < 0) { + RTE_LOG(ERR, EAL, "Invalid socket index: %u\n", + i); + continue; + } + num_pages = get_num_hugepages_on_node( dirent->d_name, socket); hpi->num_pages[socket] = num_pages; total_pages += num_pages; -- 2.7.4