[dpdk-dev] [PATCH 1/2] eal: fix potential negative return

Anatoly Burakov anatoly.burakov at intel.com
Tue Apr 17 17:42:28 CEST 2018


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.burakov at intel.com

Signed-off-by: Anatoly Burakov <anatoly.burakov at 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


More information about the dev mailing list