hikptool/0078-hikptool-nic-avoid-array-boundary-exceeded-in-hikp_n.patch
zhangyuyang 9266dc4f4d hikptool: Modify the review comments to increase the reliability of the code
Synchronize code, Modify the review comments to increase the reliability of the code

Signed-off-by: veega2022 <zhuweijia@huawei.com>
(cherry picked from commit d2a23f9ffed0201385c7864b9cd58312fb395cb6)
2024-11-26 16:32:40 +08:00

60 lines
1.9 KiB
Diff

From bc4420a4c0cb1fa85b15d671c7ebabbe534a0196 Mon Sep 17 00:00:00 2001
From: Peiyang Wang <wangpeiyang1@huawei.com>
Date: Wed, 21 Aug 2024 10:28:27 +0800
Subject: [PATCH 16/27] hikptool: nic: avoid array boundary exceeded in
hikp_nic_info.c
In hikp_nic_info.c, when using pf id or die id, the value should be not
bigger than the max value. Otherwise, array boundary exceeded might be
occurred.
Signed-off-by: Peiyang Wang <wangpeiyang1@huawei.com>
---
net/nic/nic_info/hikp_nic_info.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/net/nic/nic_info/hikp_nic_info.c b/net/nic/nic_info/hikp_nic_info.c
index 992bbf0..cd07b13 100644
--- a/net/nic/nic_info/hikp_nic_info.c
+++ b/net/nic/nic_info/hikp_nic_info.c
@@ -113,6 +113,11 @@ static void hikp_nic_info_print_cur_pf(const struct bdf_t *bdf)
uint8_t i;
int ret;
+ if (pf_id >= HIKP_MAX_PF_NUM) {
+ HIKP_ERROR_PRINT("pf_id(%u) is invalid.\n", pf_id);
+ return;
+ }
+
printf("Current function: pf%u\n", pf_id);
printf("\t%-16s %s\n", "pf mode:",
g_info_param.info.pf_info[pf_id].pf_mode ? "X86" : "ARM");
@@ -148,6 +153,11 @@ static void hikp_nic_info_print_cur_die(void)
{
uint8_t i;
+ if (g_info_param.info.pf_num > HIKP_MAX_PF_NUM) {
+ HIKP_ERROR_PRINT("pf_num(%u) is invalid.\n", g_info_param.info.pf_num);
+ return;
+ }
+
printf("Current die(chip%u-die%u) info:\n",
g_info_param.info.chip_id, g_info_param.info.die_id);
printf("revision id: %s", g_info_param.revision_id);
@@ -186,6 +196,12 @@ static bool is_bus_id_accessed(void)
{
uint8_t i;
+ if (g_info_param.accessed_die_num >= MAX_DIE_NUM) {
+ HIKP_ERROR_PRINT("accessed_die_num(%u) is invalid.\n",
+ g_info_param.accessed_die_num);
+ return false;
+ }
+
for (i = 0; i < g_info_param.accessed_die_num; i++) {
if (g_info_param.accessed_bus_id[i] == g_info_param.target.bdf.bus_id)
return true;
--
2.45.0.windows.1