diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 348171ef88..e9b4bd0b1d 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -2556,6 +2556,11 @@ QDBusConnectionPrivate::findMetaObject(const QString &service, const QString &pa if (mo) return mo; } + if (path.isEmpty()) { + error = QDBusError(QDBusError::InvalidObjectPath, "Object path cannot be empty"_L1); + lastError = error; + return nullptr; + } // introspect the target object QDBusMessage msg = QDBusMessage::createMethodCall(service, path, diff --git a/tests/auto/dbus/qdbusinterface/tst_qdbusinterface.cpp b/tests/auto/dbus/qdbusinterface/tst_qdbusinterface.cpp index 1021876b45..10edc0e322 100644 --- a/tests/auto/dbus/qdbusinterface/tst_qdbusinterface.cpp +++ b/tests/auto/dbus/qdbusinterface/tst_qdbusinterface.cpp @@ -306,6 +306,13 @@ void tst_QDBusInterface::notValid() QVERIFY(!interface.isValid()); QVERIFY(!QMetaObject::invokeMethod(&interface, "ListNames", Qt::DirectConnection)); + + // With a connection, but empty/null service and path specified + QDBusConnection con = QDBusConnection::sessionBus(); + QVERIFY(con.isConnected()); + QDBusInterface iface({}, {}, {}, con); + QVERIFY(!iface.isValid()); + QVERIFY(!QMetaObject::invokeMethod(&interface, "ListNames", Qt::DirectConnection)); } void tst_QDBusInterface::notValidDerived()