diff options
| author | xiphon <xiphon@protonmail.com> | 2019-12-17 21:49:58 +0000 |
|---|---|---|
| committer | xiphon <xiphon@protonmail.com> | 2019-12-17 21:51:04 +0000 |
| commit | 8c511722e0a431622db32957f9225cd3c8abe1ca (patch) | |
| tree | 7b4e981c30f03f30592e2425a7c0c4aba76590c8 /src/model | |
| parent | 46227bdad08e191d54e49813ee2f4c0e3c226f95 (diff) | |
| download | monzero-gui-8c511722e0a431622db32957f9225cd3c8abe1ca.tar.gz monzero-gui-8c511722e0a431622db32957f9225cd3c8abe1ca.tar.xz monzero-gui-8c511722e0a431622db32957f9225cd3c8abe1ca.zip | |
Subaddress: fix use-after-free on accessing stale Wallet API data
Diffstat (limited to 'src/model')
| -rw-r--r-- | src/model/SubaddressModel.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/model/SubaddressModel.cpp b/src/model/SubaddressModel.cpp index 3b56923e..88f80d94 100644 --- a/src/model/SubaddressModel.cpp +++ b/src/model/SubaddressModel.cpp @@ -60,18 +60,23 @@ QVariant SubaddressModel::data(const QModelIndex &index, int role) const if (!index.isValid() || index.row() < 0 || (unsigned)index.row() >= m_subaddress->count()) return {}; - Monero::SubaddressRow * sr = m_subaddress->getRow(index.row()); - if (!sr) - return {}; + QVariant result; - QVariant result = ""; - switch (role) { - case SubaddressAddressRole: - result = QString::fromStdString(sr->getAddress()); - break; - case SubaddressLabelRole: - result = index.row() == 0 ? tr("Primary address") : QString::fromStdString(sr->getLabel()); - break; + bool found = m_subaddress->getRow(index.row(), [&index, &result, &role](const Monero::SubaddressRow &subaddress) { + switch (role) { + case SubaddressAddressRole: + result = QString::fromStdString(subaddress.getAddress()); + break; + case SubaddressLabelRole: + result = index.row() == 0 ? tr("Primary address") : QString::fromStdString(subaddress.getLabel()); + break; + default: + qCritical() << "Unimplemented role" << role; + } + }); + if (!found) + { + qCritical("%s: internal error: invalid index %d", __FUNCTION__, index.row()); } return result; |
