qt5base-lts/tests/auto/corelib/kernel/qobject
Marc Mutz f5291bf8b4 Fix UB in tst_QObject::noDeclarativeParentChangedOnDestruction()
If QObjectPrivate::declarativeData is set, it is
in various places in Qt expected to point to a
QAbstractDeclarativeDataImpl, from which ownedByQml1
is unconditionally read.

In noDeclarativeParentChangedOnDestruction(), the
declarativeData pointer is, however, set to a local
QAbstractDeclarativeData instance, which, being an
empty class, has size 1 and alignment 1.

Depending on the compiler's idea of bit field order,
this code either read uninitialized data from the
dummy object, or else some random stack memory outside
any (valid) object.

What caught UBSan's attention, though, was the
difference in alignment between the two classes:

  src/corelib/kernel/qobject.cpp:917:9: runtime error: member access within misaligned address 0x7fffc9cf706f for type 'struct QAbstractDeclarativeDataImpl', which requires 4 byte alignment

Fix by providing a properly initialized object of the
correct type.

Change-Id: Iae83a949ee5a7bc98df13e35ea614c063085fa13
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2016-01-07 13:00:28 +00:00
..
signalbug fix usage of wince scope 2015-06-05 10:29:10 +00:00
test Set the Qt API level to compatibility mode in all tests. 2012-08-01 15:37:46 +02:00
.gitignore QObject-test: Reorganize subprocess. 2011-12-14 07:07:09 +01:00
qobject.pro Fixed tst_qobject signalbug silently not compiled in -fast builds. 2012-02-23 09:06:44 +01:00
tst_qobject.cpp Fix UB in tst_QObject::noDeclarativeParentChangedOnDestruction() 2016-01-07 13:00:28 +00:00