From 8b54513cdcf62047376a5d27d784ad68a8f235bf Mon Sep 17 00:00:00 2001
From: Thiago Macieira <thiago.macieira@intel.com>
Date: Mon, 30 Mar 2026 11:47:58 -0400
Subject: QDBusMetaObject: ensure custom types are normalized

The QMetaTypeInterface::name field has been expected to be normalized
since commit 4dbac23e5354638224d8d99ba3342067c015a04b from 6.0. This
code from 5.2 didn't do that, despite having been updated for 6.0. We
just never noticed because QMetaType was lenient.

That changed in commit cfcf10e0911ec778c1de112fcbbd34cea4612598
("QMetaType: Optimize unregistering of custom types") from 6.11, which
changed the unregistration code to rely on that assumption. That caused
the search for a metatype in unregisterDynamicType() to fail to find
anything and thus crash when dereferencing the end:

        auto it = aliases.find(ti->name);
        if (it->data() == ti) {

[ChangeLog][Tools][qdbus] Fixed a bug that would cause the tool to crash
on exit when querying remote objects containing complex arguments.

Fixes: QTBUG-145359
Change-Id: Ia2f22f953e28a100b0d0fffdfae6f2a6d28ac5f8
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit c4182bd5e791c6e209c5084c33e4f6a105722d5f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
---
 src/dbus/qdbusmetaobject.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/dbus/qdbusmetaobject.cpp b/src/dbus/qdbusmetaobject.cpp
index 149392f9c3c..70b861e793a 100644
--- a/src/dbus/qdbusmetaobject.cpp
+++ b/src/dbus/qdbusmetaobject.cpp
@@ -173,6 +173,7 @@ QDBusMetaObjectGenerator::findType(const QByteArray &signature,
             // type is still unknown or doesn't match back to the signature that it
             // was expected to, so synthesize a fake type
             typeName = "QDBusRawType<0x" + signature.toHex() + ">*";
+            Q_ASSERT(typeName == QMetaObject::normalizedType(typeName));
             type = registerComplexDBusType(typeName);
         }
 
@@ -195,6 +196,7 @@ QDBusMetaObjectGenerator::findType(const QByteArray &signature,
             type = qMetaTypeId<QByteArrayList>();
         } else {
             result.name = "{D-Bus type \"" + signature + "\"}";
+            result.name = QMetaObject::normalizedType(result.name);
             type = registerComplexDBusType(result.name);
         }
     } else {
-- 
cgit v1.2.3


