Crash fix in QMetaType::typeFlags.
authorJędrzej Nowacki <jedrzej.nowacki@nokia.com>
Thu, 8 Mar 2012 14:56:33 +0000 (15:56 +0100)
committerQt by Nokia <qt-info@nokia.com>
Sun, 11 Mar 2012 21:04:21 +0000 (22:04 +0100)
The function is public, so it should validate input instead of crashing

Change-Id: Id67463b0b61ab74a76c1ede7f052bdbed37822b6
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
src/corelib/kernel/qmetatype.cpp
tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp

index 0be813f..5032cf9 100644 (file)
@@ -1616,7 +1616,7 @@ private:
     static quint32 customTypeFlags(const int type)
     {
         const QVector<QCustomTypeInfo> * const ct = customTypes();
-        if (Q_UNLIKELY(!ct))
+        if (Q_UNLIKELY(!ct || type < QMetaType::User))
             return 0;
         QReadLocker locker(customTypesLock());
         if (Q_UNLIKELY(ct->count() <= type - QMetaType::User))
index 3543988..3c21a50 100644 (file)
@@ -743,6 +743,12 @@ QT_FOR_EACH_STATIC_CORE_POINTER(ADD_METATYPE_TEST_ROW)
     QTest::newRow("QPair<P,C>") << ::qMetaTypeId<QPair<P,C> >() << false << true  << false;
     QTest::newRow("QPair<P,M>") << ::qMetaTypeId<QPair<P,M> >() << true  << true  << false;
     QTest::newRow("QPair<P,P>") << ::qMetaTypeId<QPair<P,P> >() << true  << false << false;
+
+    // invalid ids.
+    QTest::newRow("-1") << -1 << false << false << false;
+    QTest::newRow("-124125534") << -124125534 << false << false << false;
+    QTest::newRow("124125534") << 124125534 << false << false << false;
+
 }
 
 void tst_QMetaType::flags()