Skip to content

Commit

Permalink
Fixed crash on getting props from uninitialized vcard4
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Jun 12, 2024
1 parent be8f6c4 commit f0b57f5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/xmpp/xmpp-im/xmpp_serverinfomanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ void ServerInfoManager::deinitialize()

const QString &ServerInfoManager::multicastService() const { return _multicastService; }

bool ServerInfoManager::hasPEP() const { return _hasPEP; }

bool ServerInfoManager::canMessageCarbons() const { return _canMessageCarbons; }

void ServerInfoManager::queryServicesList()
Expand Down Expand Up @@ -294,10 +292,12 @@ void ServerInfoManager::account_disco_finished()
// Identities
DiscoItem::Identities is = jt->item().identities();
for (const DiscoItem::Identity &i : is) {
if (i.category == "pubsub" && i.type == "pep")
if (i.category == "pubsub" && i.type == "pep") {
_hasPEP = true;
}
}
_account_features = jt->item().features();
_hasPersistentStorage = jt->item().hasPersistentStorage();
_account_features = jt->item().features();

emit featuresChanged();
}
Expand Down
10 changes: 6 additions & 4 deletions src/xmpp/xmpp-im/xmpp_serverinfomanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class ServerInfoManager : public QObject {
ServerInfoManager(XMPP::Client *client);

const QString &multicastService() const;
bool hasPEP() const;
inline bool hasPEP() const { return _hasPEP; }
inline bool hasPersistentStorage() const { return _hasPersistentStorage; }
inline const Features &server_features() const { return _server_features; }
inline const Features &account_features() const { return _account_features; }
bool canMessageCarbons() const;
Expand Down Expand Up @@ -137,9 +138,10 @@ private slots:
QMap<QString, ServiceInfo>
_servicesInfo; // all the diso#info requests for services of this server jid=>(state,info)

bool _featuresRequested;
bool _hasPEP;
bool _canMessageCarbons;
bool _featuresRequested = false;
bool _hasPEP = false;
bool _hasPersistentStorage = false;
bool _canMessageCarbons = false;
};
} // namespace XMPP

Expand Down
10 changes: 5 additions & 5 deletions src/xmpp/xmpp-im/xmpp_vcard4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ namespace {
}

template <typename ItemT>
static void fillContainer(QDomElement parent, const char *tagName, TaggedList<ItemT> &container)
static void fillContainer(QDomElement parent, const char *tagName, TaggedList<Item<ItemT>> &container)
{
auto tn = QString::fromLatin1(tagName);
for (auto e = parent.firstChildElement(tn); !e.isNull(); e = e.nextSiblingElement(tn)) {
Expand Down Expand Up @@ -644,7 +644,7 @@ QDomElement VCard::toXmlElement(QDomDocument &document) const
return {};
}

QDomElement vCardElement = document.createElement(QLatin1String("vcard"));
QDomElement vCardElement = document.createElementNS(VCARD_NAMESPACE, QLatin1String("vcard"));

VCardHelper::serializeList(vCardElement, d->fullName, QLatin1String("fn"));
if (!d->names.data.isEmpty()) {
Expand Down Expand Up @@ -947,7 +947,7 @@ void VCard::fromVCardTemp(const XMPP::VCard &tempVCard)

XMPP::VCard VCard::toVCardTemp() const
{
XMPP::VCard tempVCard;
auto tempVCard = XMPP::VCard::makeEmpty();

// Full Name
if (!d->fullName.isEmpty()) {
Expand Down Expand Up @@ -1059,15 +1059,15 @@ XMPP::VCard VCard::toVCardTemp() const

// Getters and setters implementation

PStrings VCard::fullName() const { return d->fullName; }
PStrings VCard::fullName() const { return d ? d->fullName : PStrings {}; }

void VCard::setFullName(const PStrings &fullName)
{
INIT_D();
d->fullName = fullName;
}

const PNames &VCard::names() const { return d->names; }
PNames VCard::names() const { return d ? d->names : PNames {}; }

void VCard::setNames(const PNames &names)
{
Expand Down
4 changes: 2 additions & 2 deletions src/xmpp/xmpp-im/xmpp_vcard4.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ class VCard {
PStrings fullName() const;
void setFullName(const PStrings &fullName);

const PNames &names() const;
void setNames(const PNames &names);
PNames names() const;
void setNames(const PNames &names);

PStringLists nickName() const;
void setNickName(const PStringLists &nickname);
Expand Down

0 comments on commit f0b57f5

Please sign in to comment.