From 043c7d14e8b09bfe1b242bfcf2b0a3342e3d18da Mon Sep 17 00:00:00 2001 From: Peiyang Wang 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 --- 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