From 15ac12e93efac8b2c85c9fb120806bd9ec315144 Mon Sep 17 00:00:00 2001 From: Wenchao Hao Date: Tue, 24 Nov 2020 17:14:48 +0800 Subject: iscsi_net_util: Fix NULL pointer dereference in find_vlan_dev() if_nameindex() returns NULL on error, if it returns NULL, we just print the error info and return NULL. Signed-off-by: Wenchao Hao Signed-off-by: Zhiqiang Liu Signed-off-by: Wu Bo --- usr/iscsi_net_util.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'usr') diff --git a/usr/iscsi_net_util.c b/usr/iscsi_net_util.c index c38456f..10e6fa6 100644 --- a/usr/iscsi_net_util.c +++ b/usr/iscsi_net_util.c @@ -206,6 +206,12 @@ static char *find_vlan_dev(char *netdev, int vlan_id) { } ifni = if_nameindex(); + if (!ifni) { + log_error("Failed to find netdev:%s", strerror(errno)); + close(sockfd); + return NULL; + } + for (i = 0; ifni[i].if_index && ifni[i].if_name; i++) { strlcpy(vlan_hwaddr.ifr_name, ifni[i].if_name, IFNAMSIZ); ioctl(sockfd, SIOCGIFHWADDR, &vlan_hwaddr); -- cgit v1.2.1