From f1fcdffcb53723224b811ce12b5dad9cae520714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Wed, 22 Jan 2020 13:36:46 +0100 Subject: [PATCH] fixed GH #2863: NetworkInterface::map can fail to reveal some interfaces if an earlier one can not be handled --- Net/src/NetworkInterface.cpp | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/Net/src/NetworkInterface.cpp b/Net/src/NetworkInterface.cpp index 8b9fbfad6..b59e53032 100644 --- a/Net/src/NetworkInterface.cpp +++ b/Net/src/NetworkInterface.cpp @@ -1388,9 +1388,9 @@ NetworkInterface::Map NetworkInterface::map(bool ipOnly, bool upOnly) if (getifaddrs(&ifaces) < 0) throw NetException("cannot get network adapter list"); - try + for (currIface = ifaces; currIface != 0; currIface = currIface->ifa_next) { - for (currIface = ifaces; currIface != 0; currIface = currIface->ifa_next) + try { if (!currIface->ifa_addr) continue; @@ -1462,9 +1462,14 @@ NetworkInterface::Map NetworkInterface::map(bool ipOnly, bool upOnly) } } } - } - catch (...) - { + catch (Poco::Exception&) + { + } + catch (...) + { + if (ifaces) freeifaddrs(ifaces); + throw; + } } if (ifaces) freeifaddrs(ifaces); @@ -1601,9 +1606,9 @@ NetworkInterface::Map NetworkInterface::map(bool ipOnly, bool upOnly) if (getifaddrs(&ifaces) < 0) throw NetException("cannot get network adapter list"); - try + for (iface = ifaces; iface; iface = iface->ifa_next) { - for (iface = ifaces; iface; iface = iface->ifa_next) + try { if (!iface->ifa_addr) continue; @@ -1678,13 +1683,16 @@ NetworkInterface::Map NetworkInterface::map(bool ipOnly, bool upOnly) ifIt->second.addAddress(address, subnetMask, broadcastAddress); } } - } // for interface - } - catch (...) - { - if (ifaces) freeifaddrs(ifaces); - throw; - } + } + catch (Poco::Exception&) + { + } + catch (...) + { + if (ifaces) freeifaddrs(ifaces); + throw; + } + } // for interface if (ifaces) freeifaddrs(ifaces);