hikptool/0076-hikptool-nic-check-strtol-if-it-failed-in-get_numvfs.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

36 lines
1.1 KiB
Diff

From 043c7d14e8b09bfe1b242bfcf2b0a3342e3d18da Mon Sep 17 00:00:00 2001
From: Peiyang Wang <wangpeiyang1@huawei.com>
Date: Tue, 20 Aug 2024 17:16:53 +0800
Subject: [PATCH 14/27] hikptool: nic: check strtol if it failed in
get_numvfs_by_bdf
Since strtol() can legitimately return 0, LONG_MAX, or LONG_MIN (LLONG_MAX
or LLONG_MIN for strtoll()) on both success and failure. So set errno to 0
and check it after calling.
Signed-off-by: Peiyang Wang <wangpeiyang1@huawei.com>
---
net/hikp_net_lib.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/hikp_net_lib.c b/net/hikp_net_lib.c
index 4e1e305..23adbdc 100644
--- a/net/hikp_net_lib.c
+++ b/net/hikp_net_lib.c
@@ -366,7 +366,12 @@ int get_numvfs_by_bdf(const struct bdf_t *bdf, uint8_t *numvfs)
if (ret != 0)
return ret;
+ errno = 0;
ret = (int)strtol(numvf, NULL, 0);
+ if (errno) {
+ HIKP_ERROR_PRINT("get numvfs by bdf failed, ret=%d\n", -errno);
+ return -errno;
+ }
if ((ret > UCHAR_MAX) || (ret < 0)) {
HIKP_ERROR_PRINT("get numvfs by bdf fail.\n");
return -EINVAL;
--
2.45.0.windows.1