electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 93619c8341dd57c7d4e7c3bd2a2d82bf47207919
parent 9f7e256e39176905715a0fe4018e151a8dedfccd
Author: SomberNight <somber.night@protonmail.com>
Date:   Wed, 21 Feb 2018 13:31:01 +0100

make qt gui even more resistant against ill-formed txns

see #3945

Diffstat:
Mgui/qt/main_window.py | 20++++++--------------
Mgui/qt/transaction_dialog.py | 20++++++++++++++++----
2 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -2288,25 +2288,17 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): return self.tx_from_text(file_content) def do_process_from_text(self): - from electrum.transaction import SerializationError text = text_dialog(self, _('Input raw transaction'), _("Transaction:"), _("Load transaction")) if not text: return - try: - tx = self.tx_from_text(text) - if tx: - self.show_transaction(tx) - except SerializationError as e: - self.show_critical(_("Electrum was unable to deserialize the transaction:") + "\n" + str(e)) + tx = self.tx_from_text(text) + if tx: + self.show_transaction(tx) def do_process_from_file(self): - from electrum.transaction import SerializationError - try: - tx = self.read_tx_from_file() - if tx: - self.show_transaction(tx) - except SerializationError as e: - self.show_critical(_("Electrum was unable to deserialize the transaction:") + "\n" + str(e)) + tx = self.read_tx_from_file() + if tx: + self.show_transaction(tx) def do_process_from_txid(self): from electrum import transaction diff --git a/gui/qt/transaction_dialog.py b/gui/qt/transaction_dialog.py @@ -25,6 +25,7 @@ import copy import datetime import json +import traceback from PyQt5.QtCore import * from PyQt5.QtGui import * @@ -36,15 +37,23 @@ from electrum.plugins import run_hook from electrum.util import bfh from electrum.wallet import AddTransactionException +from electrum.transaction import SerializationError from .util import * dialogs = [] # Otherwise python randomly garbage collects the dialogs... + def show_transaction(tx, parent, desc=None, prompt_if_unsaved=False): - d = TxDialog(tx, parent, desc, prompt_if_unsaved) - dialogs.append(d) - d.show() + try: + d = TxDialog(tx, parent, desc, prompt_if_unsaved) + except SerializationError as e: + traceback.print_exc(file=sys.stderr) + parent.show_critical(_("Electrum was unable to deserialize the transaction:") + "\n" + str(e)) + else: + dialogs.append(d) + d.show() + class TxDialog(QDialog, MessageBoxMixin): @@ -58,7 +67,10 @@ class TxDialog(QDialog, MessageBoxMixin): # e.g. the FX plugin. If this happens during or after a long # sign operation the signatures are lost. self.tx = copy.deepcopy(tx) - self.tx.deserialize() + try: + self.tx.deserialize() + except BaseException as e: + raise SerializationError(e) self.main_window = parent self.wallet = parent.wallet self.prompt_if_unsaved = prompt_if_unsaved