qt6-bb10/tests/auto/corelib
Jøger Hansegård a8792feaaa Fix crash in `QVariant::convert` and `QVariant::view`
`QVariant::convert` may lead to crash or produce garbage data when
attempting to convert a gadget between a pointer type and a value type,
for example from a variant holding a QLocale gadget to a QLocale*
pointer and vice versa. Similarly, `QVariant::view` may crash under the
same conditions.

The reason is that conversion is implemented through copy construction
assuming that both source and target types are either both pointers or
both values. If converting from pointer to value type, the result is
crash during destruction of the QVariant. If converting from value to
pointer type, the result is a QVariant holding a pointer to garbage
data (and possibly crash if pointer is dereferenced).

Similarly, if attempting to convert a pointer to a QObject derived type
to its value type, the system crashes, with a slightly different failure
mode. During `QVariant::convert`, a temporary `QVariant` of the target
type is created. Since objects that can not be copy constructed are
invalid for `QVariant`, the temporary is left empty without constructing
the target value. Then, when attempting to convert from a pointer type
to a value type, the temporary's destructor is incorrectly called on the
owned object. Since the owned object is never constructed, this leads to
a crash.

The proposed fix is to return false from `QMetaType::view`,
`QMetaType::canView`, `QMetaType::convert`, and `QMetaType::canConvert`
if the target type is of different 'pointedness' than the source type.

After this fix, converting and viewing gadgets and QObjects behaves the
same way as primitive types and core types, which already returned false
when converting between value type and pointer type.

Fixes: QTBUG-114797
Pick-to: 6.5 6.6
Change-Id: If5ad764a60f2f3c912070198073b28999d995f17
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-07-02 16:01:15 +02:00
..
animation QPauseAnimation test: add QNX to platforms that might fail 2023-05-25 14:06:50 +02:00
global Suppress a couple of GCC warnings 2023-06-29 15:19:52 +00:00
io QProcess/Unix: block all Unix signals between vfork() and exec() 2023-06-28 00:16:31 -07:00
ipc IPC: tst_QNativeIpcKey: rename duplicate row in test 2023-04-28 22:30:13 -05:00
itemmodels QAbstractProxyModel: delay headerDataChanged emissions when inserting/removing rows/columns 2023-06-23 16:24:27 +02:00
kernel Fix crash in `QVariant::convert` and `QVariant::view` 2023-07-02 16:01:15 +02:00
mimetypes QMimeDatabase: de-duplicate some code in the unittests 2023-05-07 14:29:28 +03:00
platform Don't add prefix for BaseName 2023-06-16 22:54:36 +03:00
plugin QLibraryPrivate: Actually merge load hints 2023-06-20 15:41:20 +02:00
serialization Suppress a couple of GCC warnings 2023-06-29 15:19:52 +00:00
text Skip the tst_QRegularExpression::threadSafety test on WASM temporarily 2023-06-26 11:58:27 +01:00
thread Handle a couple of GCC 13 warnings about dangling references 2023-06-28 01:09:58 +03:00
time Add test-cases for QDate::{start,end}OfDay() at QDateTime's bounds 2023-05-15 14:02:41 +02:00
tools Add q20::erase_if(std::vector, pred) and erase(vector, val) 2023-06-22 21:13:31 +00:00
CMakeLists.txt tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00