From: Chengchang Tang <tangchengch...@huawei.com>

The socket ID entered by user is cast to an unsigned integer. However,
the value may be an illegal negative value, which may cause some
problems. In this case, an error should be returned.

In addition, the socket ID may be an invalid positive number, which is
also processed in this patch.

Fixes: 2efb58cbab6e ("bond: new link bonding library")
Cc: sta...@dpdk.org

Signed-off-by: Chengchang Tang <tangchengch...@huawei.com>
Signed-off-by: Min Hu (Connor) <humi...@huawei.com>
---
 drivers/net/bonding/rte_eth_bond_args.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/bonding/rte_eth_bond_args.c 
b/drivers/net/bonding/rte_eth_bond_args.c
index 8c5f90d..bcc0fe3 100644
--- a/drivers/net/bonding/rte_eth_bond_args.c
+++ b/drivers/net/bonding/rte_eth_bond_args.c
@@ -207,12 +207,12 @@ bond_ethdev_parse_socket_id_kvarg(const char *key 
__rte_unused,
                return -1;
 
        errno = 0;
-       socket_id = (uint8_t)strtol(value, &endptr, 10);
+       socket_id = strtol(value, &endptr, 10);
        if (*endptr != 0 || errno != 0)
                return -1;
 
        /* validate socket id value */
-       if (socket_id >= 0) {
+       if (socket_id >= 0 && socket_id < RTE_MAX_NUMA_NODES) {
                *(uint8_t *)extra_args = (uint8_t)socket_id;
                return 0;
        }
-- 
2.7.4

Reply via email to