From e0ab9aa898fdd813c73ea3c47ffb0f9b5f80e9cf Mon Sep 17 00:00:00 2001 From: xiphon Date: Tue, 17 Dec 2019 14:18:54 +0000 Subject: SubaddressAccount: fix use-after-free bug --- src/model/SubaddressAccountModel.cpp | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'src/model/SubaddressAccountModel.cpp') diff --git a/src/model/SubaddressAccountModel.cpp b/src/model/SubaddressAccountModel.cpp index b8258296..c84b4532 100644 --- a/src/model/SubaddressAccountModel.cpp +++ b/src/model/SubaddressAccountModel.cpp @@ -59,22 +59,28 @@ QVariant SubaddressAccountModel::data(const QModelIndex &index, int role) const if (!index.isValid() || index.row() < 0 || (unsigned)index.row() >= m_subaddressAccount->count()) return {}; - Monero::SubaddressAccountRow * sr = m_subaddressAccount->getRow(index.row()); + QVariant result; - QVariant result = ""; - switch (role) { - case SubaddressAccountAddressRole: - result = QString::fromStdString(sr->getAddress()); - break; - case SubaddressAccountLabelRole: - result = QString::fromStdString(sr->getLabel()); - break; - case SubaddressAccountBalanceRole: - result = QString::fromStdString(sr->getBalance()); - break; - case SubaddressAccountUnlockedBalanceRole: - result = QString::fromStdString(sr->getUnlockedBalance()); - break; + bool found = m_subaddressAccount->getRow(index.row(), [&result, &role](const Monero::SubaddressAccountRow &row) { + switch (role) { + case SubaddressAccountAddressRole: + result = QString::fromStdString(row.getAddress()); + break; + case SubaddressAccountLabelRole: + result = QString::fromStdString(row.getLabel()); + break; + case SubaddressAccountBalanceRole: + result = QString::fromStdString(row.getBalance()); + break; + case SubaddressAccountUnlockedBalanceRole: + result = QString::fromStdString(row.getUnlockedBalance()); + break; + default: + qCritical() << "Unimplemented role" << role; + } + }); + if (!found) { + qCritical("%s: internal error: invalid index %d", __FUNCTION__, index.row()); } return result; -- cgit v1.2.3