summaryrefslogtreecommitdiffstats
path: root/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp
diff options
context:
space:
mode:
authorSami Rosendahl <ext-sami.1.rosendahl@nokia.com>2012-01-17 11:43:59 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-01-25 12:29:00 (GMT)
commit4e8e0b3e215c1b958457a9154b56f3b14a1c8518 (patch)
treee238c2251529e184c522ad8faeec7c95b0d144b3 /tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp
parentd1cd17713e6d0bd9c7a270ba675704ad244e2b13 (diff)
downloadQt-4e8e0b3e215c1b958457a9154b56f3b14a1c8518.zip
Qt-4e8e0b3e215c1b958457a9154b56f3b14a1c8518.tar.gz
Qt-4e8e0b3e215c1b958457a9154b56f3b14a1c8518.tar.bz2
Fix crashes and non-portable functionality in QDBusDemarshaller QByteArray extraction
QDBusArgument QByteArray extraction operator and QDBusDemarshaller that implements the extraction do not check the type of the extracted value. When extracting a QByteArray when the value actually is e.g. a struct of mixed types the byte array extraction will crash as it attempts to extract the struct data as a fixed array. The fix adds DBus type checks to QDBusArgument byte array extraction operator implementations. The checks invalidate extracting arrays of other types than bytes to a QByteArray that worked with the unchecked implementation. The rationale for this restriction is 1) extracting a QByteArray to a variant checks already that the array element type is byte 2) Results of extracting arrays of types wider than a byte to a QByteArray are architecture-dependent making such code inherently non-portable. Task-number: QTBUG-22840 Change-Id: Iaa284603c65d7a431a3fd020c18240cd8199ceb9 (From Qt5 commit b9acd85b2f92f887521b952f84ced9a2d1a8a57e) Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp')
-rw-r--r--tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp53
1 files changed, 53 insertions, 0 deletions
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"