From 905755304a474c942346774d930b92e3665c1bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Thu, 3 Nov 2022 13:40:18 +0100 Subject: QNetworkInformation[Win]: Catch potential exceptions Some Windows SDKs seem to throw an exception (sometimes?) when calling ConnectionProfile::NetworkAdapter. Catch the exception and ignore it, we would return Unknown anyway. And just in case it is needed, do the same for GetConnectionCost. This requires enabling exceptions for the plugin. Fixes: QTBUG-108156 Change-Id: Ie6c5adb3715578aa94ef3391afae79d9aecdc5d3 Reviewed-by: Oliver Wolff (cherry picked from commit 35e54f9b7bba9ad7b1757e0b8f7d03859a694b34) Reviewed-by: Qt Cherry-pick Bot --- .../networkinformation/networklistmanager/CMakeLists.txt | 1 + .../networklistmanager/qnetworklistmanagerevents.cpp | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/plugins/networkinformation/networklistmanager/CMakeLists.txt b/src/plugins/networkinformation/networklistmanager/CMakeLists.txt index d927d4af60..2fb65377d4 100644 --- a/src/plugins/networkinformation/networklistmanager/CMakeLists.txt +++ b/src/plugins/networkinformation/networklistmanager/CMakeLists.txt @@ -3,6 +3,7 @@ qt_internal_add_plugin(QNLMNIPlugin CLASS_NAME QNetworkListManagerNetworkInformationBackendFactory PLUGIN_TYPE networkinformation DEFAULT_IF WIN32 AND QT_FEATURE_networklistmanager + EXCEPTIONS SOURCES qnetworklistmanagernetworkinformationbackend.cpp qnetworklistmanagerevents.h qnetworklistmanagerevents.cpp diff --git a/src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp b/src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp index 5af75a89d5..787259fd65 100644 --- a/src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp +++ b/src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp @@ -186,7 +186,12 @@ QNetworkInformation::TransportMedium getTransportMedium(const ConnectionProfile if (profile.IsWlanConnectionProfile()) return QNetworkInformation::TransportMedium::WiFi; - NetworkAdapter adapter = profile.NetworkAdapter(); + NetworkAdapter adapter(nullptr); + try { + adapter = profile.NetworkAdapter(); + } catch (...) { + // pass, we will return Unknown anyway + } if (adapter == nullptr) return QNetworkInformation::TransportMedium::Unknown; @@ -209,7 +214,14 @@ QNetworkInformation::TransportMedium getTransportMedium(const ConnectionProfile [[nodiscard]] bool getMetered(const ConnectionProfile &profile) { - ConnectionCost cost = profile.GetConnectionCost(); + ConnectionCost cost(nullptr); + try { + cost = profile.GetConnectionCost(); + } catch (...) { + // pass, we return false if we get an empty object back anyway + } + if (cost == nullptr) + return false; NetworkCostType type = cost.NetworkCostType(); return type == NetworkCostType::Fixed || type == NetworkCostType::Variable; } -- cgit v1.2.3