qt5base-lts/tests/auto/corelib/kernel
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
..
qapplicationstatic Change the license of all CMakeLists.txt and *.cmake files to BSD 2022-08-23 23:58:42 +02:00
qcoreapplication Fix sending deferred delete events when posted before outermost loop 2023-06-09 16:31:35 +02:00
qdeadlinetimer QDeadlineTimer: make it so any negative millisecond count is "forever" 2023-05-11 00:28:49 -07:00
qelapsedtimer QElapsedTimer: rewrite using std::chrono::steady_clock everywhere 2023-04-18 19:23:42 -03:00
qeventdispatcher QThread: add sleep(std::chrono::nanoseconds) overload 2023-03-13 23:26:28 +02:00
qeventloop tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qjnienvironment CMake: Remove direct qt_android_generate_deployment_settings call 2022-12-15 20:23:28 +01:00
qjniobject CMake: Remove direct qt_android_generate_deployment_settings call 2022-12-15 20:23:28 +01:00
qjnitypes JNI: add generic support for array-types 2022-10-10 20:19:30 +02:00
qmath tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qmetacontainer QMetaContainer: Allow retrieving the d pointer 2023-06-21 00:04:04 +02:00
qmetaenum tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qmetamethod tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qmetaobject Fix QMetaObject::invokeMethod for free functions and std::bind 2023-05-11 19:36:55 +02:00
qmetaobjectbuilder moc: Record types of enumerations 2023-03-31 17:42:58 +02:00
qmetaproperty tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qmetatype QMetaType: Provide underlyingType for enums 2023-03-28 10:59:53 +02:00
qmimedata tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qobject Pacify MSVC compiler incorrectly warning about unused variable 2023-06-22 13:20:26 +00:00
qpermission Simplify the creation of APIs that take a callback 2023-04-26 22:06:31 +02:00
qpointer QPointer: also make conversion to pointer-to-const work 2023-05-11 08:10:16 +00:00
qproperty QBindable: Fix out-of-bound access in non-bindable property support code 2023-06-20 05:55:52 +00:00
qsignalblocker tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qsignalmapper tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qsocketnotifier QTestEventLoop: add enterLoop(std::chrono::milliseconds) overload 2023-03-03 21:36:48 +02:00
qtimer tst_QTimer: ensure that timer activation respects start order 2023-06-06 17:47:00 -07:00
qtranslator tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qvariant Fix crash in QVariant::convert and QVariant::view 2023-07-02 16:01:15 +02:00
qwineventnotifier tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qwinregistrykey QWinRegistryKey: Fix how we handle the default value, take 2 2022-10-28 09:27:13 +00:00
CMakeLists.txt tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00