[dpdk-dev,1/2] eal: fix potential negative return
Checks
Commit Message
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@intel.com
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
Comments
On 4/17/2018 11:42 PM, Anatoly Burakov wrote:
> 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@intel.com
>
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Reviewed-by: Jianfeng Tan <jianfeng.tan@intel.com>
@@ -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;