From 09b015f61191d5b41a37a4a77a0de05d6cc88600 Mon Sep 17 00:00:00 2001 From: Aiwe Date: Fri, 29 Jul 2022 12:48:12 +0300 Subject: [PATCH] Proper import account keys instead of memcpy because AccountKeys is non-trivially copyable type --- src/gui/MainWindow.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 86e0cd947..14ff89bb3 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -22,9 +22,10 @@ #include "MainWindow.h" -#include -#include -#include +#include "Common/Base58.h" +#include "Common/StringTools.h" +#include "Common/Util.h" +#include "CryptoNoteCore/CryptoNoteTools.h" #include "AboutDialog.h" #include "AnimatedLabel.h" #include "AddressBookModel.h" @@ -484,7 +485,10 @@ void MainWindow::importKey() { CryptoNote::AccountKeys keys; if (Tools::Base58::decode_addr(keyString.toStdString(), addressPrefix, data) && addressPrefix == CurrencyAdapter::instance().getAddressPrefix() && data.size() == sizeof(keys)) { - std::memcpy(&keys, data.data(), sizeof(keys)); + //std::memcpy(&keys, data.data(), sizeof(keys)); + if (!fromBinaryArray(keys, Common::asBinaryArray(data))) { + QMessageBox::warning(this, tr("Wallet keys are not valid"), tr("Failed to parse account keys"), QMessageBox::Ok); + } if (WalletAdapter::instance().isOpen()) { WalletAdapter::instance().close(); }