Skip to content

Commit

Permalink
ExportData: Prevent storing of data of unregistered extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
lnjX committed Aug 18, 2024
1 parent 6974bbb commit ee72d41
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/client/QXmppAccountMigrationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ void QXmppExportData::registerExtensionInternal(std::type_index type, ExtensionP
accountDataSerializers().emplace(type, serialize);
}

bool QXmppExportData::isExtensionRegistered(std::type_index type)
{
return accountDataSerializers().contains(type);
}

struct QXmppAccountMigrationManagerPrivate {
template<typename T = Success>
using Result = std::variant<T, QXmppError>;
Expand Down
5 changes: 5 additions & 0 deletions src/client/QXmppAccountMigrationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class QXMPP_EXPORT QXmppExportData
template<typename T>
void setExtension(T &&value)
{
Q_ASSERT(isExtensionRegistered<T>());
setExtension(std::any(std::move(value)));
}

Expand Down Expand Up @@ -70,6 +71,9 @@ class QXMPP_EXPORT QXmppExportData
registerExtensionInternal(std::type_index(typeid(T)), parseAny, serializeAny, tagName, xmlns);
}

template<typename T>
static bool isExtensionRegistered() { return isExtensionRegistered(std::type_index(typeid(T))); }

private:
friend class QXmppAccountMigrationManager;
friend class tst_QXmppAccountMigrationManager;
Expand All @@ -78,6 +82,7 @@ class QXMPP_EXPORT QXmppExportData
void setExtension(std::any value);

static void registerExtensionInternal(std::type_index, ExtensionParser<std::any>, ExtensionSerializer<std::any>, QStringView tagName, QStringView xmlns);
static bool isExtensionRegistered(std::type_index);

QSharedDataPointer<QXmppExportDataPrivate> d;
};
Expand Down

0 comments on commit ee72d41

Please sign in to comment.