Skip to content

Commit

Permalink
[GUI] Guard access to TxDetailDialog::acceptTx
Browse files Browse the repository at this point in the history
Throw a generic GUI exception if it is called on non-confirmation
dialogs
  • Loading branch information
random-zebra committed Mar 20, 2020
1 parent 7ec6c13 commit 52157ce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ class QUrl;
class QWidget;
QT_END_NAMESPACE

/*
* General GUI exception
*/
class GUIException : public std::exception
{
public:
std::string message;
GUIException(const std::string &message) : message(message) {}
};

/** Utility functions used by the PIVX Qt UI.
*/
namespace GUIUtil
Expand Down
16 changes: 10 additions & 6 deletions src/qt/pivx/sendconfirmdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ void TxDetailDialog::setData(WalletModel *model, WalletModelTransaction &tx){

void TxDetailDialog::acceptTx()
{
if (isConfirmDialog) {
this->confirm = true;
this->sendStatus = model->sendCoins(*this->tx);
}
if (!isConfirmDialog)
throw GUIException(strprintf("%s called on non confirm dialog", __func__));
this->confirm = true;
this->sendStatus = model->sendCoins(*this->tx);
accept();
}

Expand Down Expand Up @@ -232,9 +232,13 @@ void TxDetailDialog::keyPressEvent(QKeyEvent *event)
if (event->type() == QEvent::KeyPress) {
QKeyEvent* ke = static_cast<QKeyEvent*>(event);
// Detect Enter key press
if (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return) acceptTx();
if (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return) {
if (isConfirmDialog) acceptTx();
else accept();
}
// Detect Esc key press
if (ke->key() == Qt::Key_Escape) closeDialog();
if (ke->key() == Qt::Key_Escape)
closeDialog();
}
}

Expand Down

0 comments on commit 52157ce

Please sign in to comment.