Index | Thread | Search

From:
Rafael Sadowski <rafael@sizeofvoid.org>
Subject:
Fix QNetworkInformation useage
To:
ports@openbsd.org
Date:
Sat, 2 Aug 2025 18:47:02 +0200

Download raw body.

Thread
  • Rafael Sadowski:

    Fix QNetworkInformation useage

Here is a diff to fix QNetworkInformation usage in some ports.
QNetworkInformation::instance provides a pointer and if the
::loadBackendBy* call fails it is null. Unfortunately there is no
working NetworkManager (QGNetworkManager plugin also not working
properly) and ::instance provides a null pointer on OpenBSD.

https://doc.qt.io/qt-6/qnetworkinformation.html

Some programs do not check this case. This diff tries to fix the situation.

Feedback?

Index: x11/kde-applications/akonadi/Makefile
===================================================================
RCS file: /cvs/ports/x11/kde-applications/akonadi/Makefile,v
diff -u -p -r1.30 Makefile
--- x11/kde-applications/akonadi/Makefile	2 Aug 2025 07:45:05 -0000	1.30
+++ x11/kde-applications/akonadi/Makefile	2 Aug 2025 16:38:09 -0000
@@ -1,7 +1,7 @@
 COMMENT =	PIM Storage Service
 DISTNAME =	akonadi-${VERSION}
 CATEGORIES =	databases productivity
-REVISION =	0
+REVISION =	1
 
 HOMEPAGE =	https://kontact.kde.org
 
Index: x11/kde-applications/akonadi/patches/patch-src_agentbase_agentbase_cpp
===================================================================
RCS file: /cvs/ports/x11/kde-applications/akonadi/patches/patch-src_agentbase_agentbase_cpp,v
diff -u -p -r1.1 patch-src_agentbase_agentbase_cpp
--- x11/kde-applications/akonadi/patches/patch-src_agentbase_agentbase_cpp	2 Aug 2025 07:45:05 -0000	1.1
+++ x11/kde-applications/akonadi/patches/patch-src_agentbase_agentbase_cpp	2 Aug 2025 16:38:09 -0000
@@ -1,18 +1,40 @@
-QNetworkInformation::Reachability is not available on OpenBSD, stop using it
-and fallback to the default one.
+Check if QNetworkInformation::loadBackendByFeatures is successful otherwise
+avoid nullptr access
 
 Index: src/agentbase/agentbase.cpp
 --- src/agentbase/agentbase.cpp.orig
 +++ src/agentbase/agentbase.cpp
-@@ -901,7 +901,10 @@ void AgentBase::setNeedsNetwork(bool needsNetwork)
+@@ -720,7 +720,7 @@ void AgentBasePrivate::slotNetworkStatusChange(bool is
+ 
+ void AgentBasePrivate::slotResumedFromSuspend()
+ {
+-    if (mNeedsNetwork) {
++    if (mNeedsNetwork && QNetworkInformation::instance()) {
+         slotNetworkStatusChange(QNetworkInformation::instance()->reachability() != QNetworkInformation::Reachability::Online);
+     }
+ }
+@@ -901,10 +901,11 @@ void AgentBase::setNeedsNetwork(bool needsNetwork)
      }
  
      d->mNeedsNetwork = needsNetwork;
 -    QNetworkInformation::loadBackendByFeatures(QNetworkInformation::Feature::Reachability);
-+    if (!QNetworkInformation::loadBackendByFeatures(QNetworkInformation::Feature::Reachability)) {
-+         // Fallback
-+         QNetworkInformation::loadDefaultBackend();
+-    connect(QNetworkInformation::instance(), &QNetworkInformation::reachabilityChanged, this, [d](auto reachability) {
+-        d->slotNetworkStatusChange(reachability == QNetworkInformation::Reachability::Online);
+-    });
++    if (QNetworkInformation::loadBackendByFeatures(QNetworkInformation::Feature::Reachability)) {
++         connect(QNetworkInformation::instance(), &QNetworkInformation::reachabilityChanged, this, [d](auto reachability) {
++                 d->slotNetworkStatusChange(reachability == QNetworkInformation::Reachability::Online);
++                 });
 +    }
-     connect(QNetworkInformation::instance(), &QNetworkInformation::reachabilityChanged, this, [d](auto reachability) {
-         d->slotNetworkStatusChange(reachability == QNetworkInformation::Reachability::Online);
-     });
+ }
+ 
+ void AgentBase::setOnline(bool state)
+@@ -947,7 +948,7 @@ void AgentBase::setTemporaryOffline(int makeOnlineInSe
+ void AgentBase::setOnlineInternal(bool state)
+ {
+     Q_D(AgentBase);
+-    if (state && d->mNeedsNetwork) {
++    if (state && d->mNeedsNetwork && QNetworkInformation::instance()) {
+         if (QNetworkInformation::instance()->reachability() != QNetworkInformation::Reachability::Online) {
+             // Don't go online if the resource needs network but there is none
+             state = false;
Index: x11/kde-applications/kget/Makefile
===================================================================
RCS file: /cvs/ports/x11/kde-applications/kget/Makefile,v
diff -u -p -r1.25 Makefile
--- x11/kde-applications/kget/Makefile	2 May 2025 06:11:27 -0000	1.25
+++ x11/kde-applications/kget/Makefile	2 Aug 2025 16:38:10 -0000
@@ -1,6 +1,7 @@
 COMMENT =	download manager for KDE
 DISTNAME =	kget-${VERSION}
 CATEGORIES =	net www
+REVISION =	0
 
 HOMEPAGE =	https://apps.kde.org/kget
 
Index: x11/kde-applications/kget/patches/patch-core_kget_cpp
===================================================================
RCS file: x11/kde-applications/kget/patches/patch-core_kget_cpp
diff -N x11/kde-applications/kget/patches/patch-core_kget_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/kde-applications/kget/patches/patch-core_kget_cpp	2 Aug 2025 16:38:10 -0000
@@ -0,0 +1,30 @@
+Check if QNetworkInformation::loadBackendByFeatures is successful otherwise
+avoid nullptr access
+
+Index: core/kget.cpp
+--- core/kget.cpp.orig
++++ core/kget.cpp
+@@ -1224,8 +1224,10 @@ GenericObserver::GenericObserver(QObject *parent)
+     , m_save(nullptr)
+     , m_finishAction(nullptr)
+ {
+-    QNetworkInformation::loadBackendByFeatures(QNetworkInformation::Feature::Reachability);
+-    KGet::setHasNetworkConnection(QNetworkInformation::instance()->reachability() == QNetworkInformation::Reachability::Online);
++    bool isBackendLoaded = QNetworkInformation::loadBackendByFeatures(QNetworkInformation::Feature::Reachability);
++    if (isBackendLoaded) {
++        KGet::setHasNetworkConnection(QNetworkInformation::instance()->reachability() == QNetworkInformation::Reachability::Online);
++    }
+ 
+     connect(KGet::model(), &TransferTreeModel::groupRemovedEvent, this, &GenericObserver::groupRemovedEvent);
+     connect(KGet::model(), SIGNAL(transfersAddedEvent(QList<TransferHandler *>)), SLOT(transfersAddedEvent(QList<TransferHandler *>)));
+@@ -1239,7 +1241,9 @@ GenericObserver::GenericObserver(QObject *parent)
+             SLOT(groupsChangedEvent(QMap<TransferGroupHandler *, TransferGroup::ChangesFlags>)));
+     connect(KGet::model(), &TransferTreeModel::transferMovedEvent, this, &GenericObserver::transferMovedEvent);
+ 
+-    connect(QNetworkInformation::instance(), &QNetworkInformation::reachabilityChanged, this, &GenericObserver::slotNetworkStatusChanged);
++    if (isBackendLoaded) {
++        connect(QNetworkInformation::instance(), &QNetworkInformation::reachabilityChanged, this, &GenericObserver::slotNetworkStatusChanged);
++    }
+ }
+ 
+ GenericObserver::~GenericObserver()
Index: x11/kde-applications/pimcommon/Makefile
===================================================================
RCS file: /cvs/ports/x11/kde-applications/pimcommon/Makefile,v
diff -u -p -r1.29 Makefile
--- x11/kde-applications/pimcommon/Makefile	2 May 2025 06:11:33 -0000	1.29
+++ x11/kde-applications/pimcommon/Makefile	2 Aug 2025 16:38:10 -0000
@@ -1,6 +1,7 @@
 COMMENT =	common libraries for KDE PIM
 DISTNAME =	pimcommon-${VERSION}
 CATEGORIES =	devel
+REVISION =	0
 
 SHARED_LIBS +=	KPim6PimCommon            0.1 # 0.0
 SHARED_LIBS +=	KPim6PimCommonAkonadi     1.0 # 0.0
Index: x11/kde-applications/pimcommon/patches/patch-src_pimcommon_network_networkmanager_cpp
===================================================================
RCS file: x11/kde-applications/pimcommon/patches/patch-src_pimcommon_network_networkmanager_cpp
diff -N x11/kde-applications/pimcommon/patches/patch-src_pimcommon_network_networkmanager_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/kde-applications/pimcommon/patches/patch-src_pimcommon_network_networkmanager_cpp	2 Aug 2025 16:38:10 -0000
@@ -0,0 +1,21 @@
+Check if QNetworkInformation::loadBackendByFeatures is successful otherwise
+avoid nullptr access
+
+Index: src/pimcommon/network/networkmanager.cpp
+--- src/pimcommon/network/networkmanager.cpp.orig
++++ src/pimcommon/network/networkmanager.cpp
+@@ -14,9 +14,11 @@ Q_GLOBAL_STATIC(NetworkManager, s_pNetworkManagerSelf)
+ NetworkManager::NetworkManager(QObject *parent)
+     : QObject(parent)
+ {
+-    QNetworkInformation::instance()->loadBackendByFeatures(QNetworkInformation::Feature::Reachability);
+-    connect(QNetworkInformation::instance(), &QNetworkInformation::reachabilityChanged, this, &NetworkManager::refreshStatus);
+-    connect(QNetworkInformation::instance(), &QNetworkInformation::isBehindCaptivePortalChanged, this, &NetworkManager::refreshStatus);
++    bool isBackendLoaded = QNetworkInformation::loadBackendByFeatures(QNetworkInformation::Feature::Reachability);
++    if (isBackendLoaded) {
++        connect(QNetworkInformation::instance(), &QNetworkInformation::reachabilityChanged, this, &NetworkManager::refreshStatus);
++        connect(QNetworkInformation::instance(), &QNetworkInformation::isBehindCaptivePortalChanged, this, &NetworkManager::refreshStatus);
++    }
+     refreshStatus();
+ }
+ 
Index: x11/kde-applications/pimcommon/patches/patch-src_pimcommonakonadi_addressline_addresslineedit_addresseelineeditmanager_cpp
===================================================================
RCS file: x11/kde-applications/pimcommon/patches/patch-src_pimcommonakonadi_addressline_addresslineedit_addresseelineeditmanager_cpp
diff -N x11/kde-applications/pimcommon/patches/patch-src_pimcommonakonadi_addressline_addresslineedit_addresseelineeditmanager_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/kde-applications/pimcommon/patches/patch-src_pimcommonakonadi_addressline_addresslineedit_addresseelineeditmanager_cpp	2 Aug 2025 16:38:10 -0000
@@ -0,0 +1,16 @@
+Check if QNetworkInformation::loadBackendByFeatures is successful otherwise
+avoid nullptr access
+
+Index: src/pimcommonakonadi/addressline/addresslineedit/addresseelineeditmanager.cpp
+--- src/pimcommonakonadi/addressline/addresslineedit/addresseelineeditmanager.cpp.orig
++++ src/pimcommonakonadi/addressline/addresslineedit/addresseelineeditmanager.cpp
+@@ -118,7 +118,8 @@ void AddresseeLineEditManager::setAddressLineEdit(Addr
+ 
+ bool AddresseeLineEditManager::isOnline() const
+ {
+-    if (QNetworkInformation::loadBackendByFeatures(QNetworkInformation::Feature::Reachability)) {
++    bool isBackendLoaded = QNetworkInformation::loadBackendByFeatures(QNetworkInformation::Feature::Reachability);
++    if (isBackendLoaded) {
+         return QNetworkInformation::instance()->reachability() == QNetworkInformation::Reachability::Online
+             && !QNetworkInformation::instance()->isBehindCaptivePortal();
+     } else {
Index: x11/kde-plasma/plasma-workspace/Makefile
===================================================================
RCS file: /cvs/ports/x11/kde-plasma/plasma-workspace/Makefile,v
diff -u -p -r1.25 Makefile
--- x11/kde-plasma/plasma-workspace/Makefile	2 Aug 2025 09:16:38 -0000	1.25
+++ x11/kde-plasma/plasma-workspace/Makefile	2 Aug 2025 16:38:10 -0000
@@ -1,6 +1,6 @@
 COMMENT =	various components needed to run a Plasma-based environment
 DISTNAME =	plasma-workspace-${VERSION}
-REVISION =	0
+REVISION =	1
 
 SHARED_LIBS +=  colorcorrect              1.0 # 0.0
 SHARED_LIBS +=  kfontinst                 1.0 # 0.0
Index: x11/kde-plasma/plasma-workspace/patches/patch-dataengines_weather_weatherengine_cpp
===================================================================
RCS file: /cvs/ports/x11/kde-plasma/plasma-workspace/patches/patch-dataengines_weather_weatherengine_cpp,v
diff -u -p -r1.1 patch-dataengines_weather_weatherengine_cpp
--- x11/kde-plasma/plasma-workspace/patches/patch-dataengines_weather_weatherengine_cpp	2 Aug 2025 09:16:38 -0000	1.1
+++ x11/kde-plasma/plasma-workspace/patches/patch-dataengines_weather_weatherengine_cpp	2 Aug 2025 16:38:10 -0000
@@ -4,15 +4,43 @@ and fallback to the default one.
 Index: dataengines/weather/weatherengine.cpp
 --- dataengines/weather/weatherengine.cpp.orig
 +++ dataengines/weather/weatherengine.cpp
-@@ -25,7 +25,10 @@ WeatherEngine::WeatherEngine(QObject *parent)
+@@ -25,8 +25,9 @@ WeatherEngine::WeatherEngine(QObject *parent)
      // Globally notify all plugins to remove their sources (and unload plugin)
      connect(this, &Plasma5Support::DataEngine::sourceRemoved, this, &WeatherEngine::removeIonSource);
  
 -    QNetworkInformation::load(QNetworkInformation::Feature::Reachability);
-+    if (!QNetworkInformation::loadBackendByFeatures(QNetworkInformation::Feature::Reachability)) {
-+         // Fallback
-+         QNetworkInformation::loadDefaultBackend();
+-    connect(QNetworkInformation::instance(), &QNetworkInformation::reachabilityChanged, this, &WeatherEngine::onOnlineStateChanged);
++    if (QNetworkInformation::loadBackendByFeatures(QNetworkInformation::Feature::Reachability)) {
++         connect(QNetworkInformation::instance(), &QNetworkInformation::reachabilityChanged, this, &WeatherEngine::onOnlineStateChanged);
 +    }
-     connect(QNetworkInformation::instance(), &QNetworkInformation::reachabilityChanged, this, &WeatherEngine::onOnlineStateChanged);
  
      // Get the list of available plugins but don't load them
+     connect(KSycoca::self(), &KSycoca::databaseChanged, this, &WeatherEngine::updateIonList);
+@@ -124,8 +125,11 @@ bool WeatherEngine::sourceRequestEvent(const QString &
+     // is down. when it comes up again, then it will be refreshed
+     ion->connectSource(source, this);
+ 
+-    qCDebug(WEATHER) << "sourceRequestEvent(): Network is: " << QNetworkInformation::instance()->reachability();
+-    if (QNetworkInformation::instance()->reachability() != QNetworkInformation::Reachability::Online) {
++    if (QNetworkInformation::instance())
++        qCDebug(WEATHER) << "sourceRequestEvent(): Network is: " << QNetworkInformation::instance()->reachability();
++
++    if (QNetworkInformation::instance() &&
++        QNetworkInformation::instance()->reachability() != QNetworkInformation::Reachability::Online) {
+         setData(source, Data());
+         return true;
+     }
+@@ -143,8 +147,11 @@ bool WeatherEngine::sourceRequestEvent(const QString &
+  */
+ bool WeatherEngine::updateSourceEvent(const QString &source)
+ {
+-    qCDebug(WEATHER) << "updateSourceEvent(): Network is: " << QNetworkInformation::instance()->reachability();
+-    if (QNetworkInformation::instance()->reachability() != QNetworkInformation::Reachability::Online) {
++    if (QNetworkInformation::instance())
++        qCDebug(WEATHER) << "updateSourceEvent(): Network is: " << QNetworkInformation::instance()->reachability();
++
++    if (QNetworkInformation::instance() &&
++        QNetworkInformation::instance()->reachability() != QNetworkInformation::Reachability::Online) {
+         return false;
+     }
+