diff options
author | Wenchao Hao <haowenchao@huawei.com> | 2020-11-24 17:14:48 +0800 |
---|---|---|
committer | Wenchao Hao <haowenchao@huawei.com> | 2020-12-12 11:44:17 +0800 |
commit | 15ac12e93efac8b2c85c9fb120806bd9ec315144 (patch) | |
tree | 1ffaafc503819f7ceabf949229af0368b03f6731 /usr | |
parent | 86d3dae4d3e6030dfc5dee9712ae8fccd5262f5f (diff) | |
download | open-iscsi-15ac12e93efac8b2c85c9fb120806bd9ec315144.tar.gz |
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 <haowenchao@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: Wu Bo <wubo40@huawei.com>
Diffstat (limited to 'usr')
-rw-r--r-- | usr/iscsi_net_util.c | 6 |
1 files changed, 6 insertions, 0 deletions
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); |