From ce3d9fb3b3ec1f23d76b04a8593680d7eeee689d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 29 Apr 2010 13:14:09 +0200 Subject: Fix crash in QDBusInterface when invoking a method in a derived class. If metaObject is 0 and the signal or slot is in a class deriving from QDBusInterface, this would lead to a crash. Deriving from QDBusInterface is very unusual and usually indicates misunderstanding of QtDBus, but the fix is correct. Task-number: https://projects.maemo.org/bugzilla/show_bug.cgi?id=165175 Patch-By: Maemo developer Reviewed-by: Thiago Macieira --- src/dbus/qdbusinterface.cpp | 2 +- tests/auto/qdbusinterface/tst_qdbusinterface.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/dbus/qdbusinterface.cpp b/src/dbus/qdbusinterface.cpp index 300f425..56d5231 100644 --- a/src/dbus/qdbusinterface.cpp +++ b/src/dbus/qdbusinterface.cpp @@ -258,7 +258,7 @@ void *QDBusInterface::qt_metacast(const char *_clname) int QDBusInterface::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QDBusAbstractInterface::qt_metacall(_c, _id, _a); - if (_id < 0 || !d_func()->isValid) + if (_id < 0 || !d_func()->isValid || !d_func()->metaObject) return _id; return d_func()->metacall(_c, _id, _a); } diff --git a/tests/auto/qdbusinterface/tst_qdbusinterface.cpp b/tests/auto/qdbusinterface/tst_qdbusinterface.cpp index 826bd70..d8ff2d3 100644 --- a/tests/auto/qdbusinterface/tst_qdbusinterface.cpp +++ b/tests/auto/qdbusinterface/tst_qdbusinterface.cpp @@ -157,6 +157,18 @@ public slots: } }; +class DerivedFromQDBusInterface: public QDBusInterface +{ + Q_OBJECT +public: + DerivedFromQDBusInterface() + : QDBusInterface("com.example.Test", "/") + {} + +public slots: + void method() {} +}; + // helper function void emitSignal(const QString &interface, const QString &name, const QString &arg) { @@ -183,6 +195,7 @@ private slots: void notConnected(); void notValid(); + void notValidDerived(); void invalidAfterServiceOwnerChanged(); void introspect(); void callMethod(); @@ -219,6 +232,7 @@ void tst_QDBusInterface::notConnected() connection); QVERIFY(!interface.isValid()); + QVERIFY(!QMetaObject::invokeMethod(&interface, "ListNames", Qt::DirectConnection)); } void tst_QDBusInterface::notValid() @@ -230,6 +244,14 @@ void tst_QDBusInterface::notValid() connection); QVERIFY(!interface.isValid()); + QVERIFY(!QMetaObject::invokeMethod(&interface, "ListNames", Qt::DirectConnection)); +} + +void tst_QDBusInterface::notValidDerived() +{ + DerivedFromQDBusInterface c; + QVERIFY(!c.isValid()); + QMetaObject::invokeMethod(&c, "method", Qt::DirectConnection); } void tst_QDBusInterface::invalidAfterServiceOwnerChanged() -- cgit v0.12