summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/dbus/qdbusargument_p.h1
-rw-r--r--src/dbus/qdbusdemarshaller.cpp13
-rw-r--r--tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp53
3 files changed, 65 insertions, 2 deletions
diff --git a/src/dbus/qdbusargument_p.h b/src/dbus/qdbusargument_p.h
index e977c99..c04e458 100644
--- a/src/dbus/qdbusargument_p.h
+++ b/src/dbus/qdbusargument_p.h
@@ -213,6 +213,7 @@ private:
QDBusObjectPath toObjectPathUnchecked();
QDBusSignature toSignatureUnchecked();
QStringList toStringListUnchecked();
+ QByteArray toByteArrayUnchecked();
};
inline QDBusMarshaller *QDBusArgumentPrivate::marshaller()
diff --git a/src/dbus/qdbusdemarshaller.cpp b/src/dbus/qdbusdemarshaller.cpp
index be19b00..215e6a1 100644
--- a/src/dbus/qdbusdemarshaller.cpp
+++ b/src/dbus/qdbusdemarshaller.cpp
@@ -272,7 +272,7 @@ QVariant QDBusDemarshaller::toVariantInternal()
switch (q_dbus_message_iter_get_element_type(&iterator)) {
case DBUS_TYPE_BYTE:
// QByteArray
- return toByteArray();
+ return toByteArrayUnchecked();
case DBUS_TYPE_STRING:
return toStringListUnchecked();
case DBUS_TYPE_DICT_ENTRY:
@@ -339,7 +339,7 @@ QStringList QDBusDemarshaller::toStringList()
return QStringList();
}
-QByteArray QDBusDemarshaller::toByteArray()
+QByteArray QDBusDemarshaller::toByteArrayUnchecked()
{
DBusMessageIter sub;
q_dbus_message_iter_recurse(&iterator, &sub);
@@ -350,6 +350,15 @@ QByteArray QDBusDemarshaller::toByteArray()
return QByteArray(data,len);
}
+QByteArray QDBusDemarshaller::toByteArray()
+{
+ if (q_dbus_message_iter_get_arg_type(&iterator) == DBUS_TYPE_ARRAY
+ && q_dbus_message_iter_get_element_type(&iterator) == DBUS_TYPE_BYTE) {
+ return toByteArrayUnchecked();
+ }
+ return QByteArray();
+}
+
bool QDBusDemarshaller::atEnd()
{
// dbus_message_iter_has_next is broken if the list has one single element
diff --git a/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp b/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp
index 0ac917c..701f7e5 100644
--- a/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp
+++ b/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp
@@ -102,6 +102,9 @@ private slots:
void demarshallInvalidStringList_data();
void demarshallInvalidStringList();
+ void demarshallInvalidByteArray_data();
+ void demarshallInvalidByteArray();
+
private:
int fileDescriptorForTest();
@@ -1435,5 +1438,55 @@ void tst_QDBusMarshall::demarshallInvalidStringList()
QVERIFY(receiveArg.atEnd());
}
+void tst_QDBusMarshall::demarshallInvalidByteArray_data()
+{
+ addBasicTypesColumns();
+
+ // None of the basic types should demarshall to a QByteArray
+ basicNumericTypes_data();
+ basicStringTypes_data();
+
+ // Arrays of other types than byte should not demarshall to a QByteArray
+ QList<bool> bools;
+ QTest::newRow("empty array of bool") << qVariantFromValue(bools);
+ bools << true << false << true;
+ QTest::newRow("non-empty array of bool") << qVariantFromValue(bools);
+
+ // Structures should not demarshall to a QByteArray
+ QTest::newRow("struct of bytes")
+ << qVariantFromValue(QVariantList() << uchar(1) << uchar(2));
+
+ QTest::newRow("struct of mixed types")
+ << qVariantFromValue(QVariantList() << int(42) << QString("foo") << double(3.14));
+}
+
+void tst_QDBusMarshall::demarshallInvalidByteArray()
+{
+ QFETCH(QVariant, value);
+
+ QDBusConnection con = QDBusConnection::sessionBus();
+
+ QVERIFY(con.isConnected());
+
+ QDBusMessage msg = QDBusMessage::createMethodCall(serviceName, objectPath,
+ interfaceName, "ping");
+ QDBusArgument sendArg;
+ sendArg.beginStructure();
+ sendArg.appendVariant(value);
+ sendArg.endStructure();
+ msg.setArguments(QVariantList() << qVariantFromValue(sendArg));
+ QDBusMessage reply = con.call(msg);
+
+ const QDBusArgument receiveArg = qvariant_cast<QDBusArgument>(reply.arguments().at(0));
+ receiveArg.beginStructure();
+
+ QByteArray receiveValue;
+ receiveArg >> receiveValue;
+ QCOMPARE(receiveValue, QByteArray());
+
+ receiveArg.endStructure();
+ QVERIFY(receiveArg.atEnd());
+}
+
QTEST_MAIN(tst_QDBusMarshall)
#include "tst_qdbusmarshall.moc"