From ba594dd5ace69be91935450b7879c322ffd27669 Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 13 Jun 2023 17:06:56 +0200 Subject: [PATCH] additional error handling for wallet2 and simplewallet --- src/simplewallet/simplewallet.cpp | 8 ++++++++ src/wallet/wallet2.cpp | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 0b0292c3..3e52378a 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -1808,11 +1808,13 @@ bool simple_wallet::deploy_new_asset(const std::vector &args) if (!args.size() || args.size() > 1) { fail_msg_writer() << "invalid arguments count: " << args.size() << ", expected 1"; + return true; } bool r = epee::serialization::load_t_from_json_file(adb, args[0]); if (!r) { fail_msg_writer() << "Failed to load json file with asset specification: " << args[0]; + return true; } tx_destination_entry td = AUTO_VAL_INIT(td); td.addr.push_back(m_wallet->get_account().get_public_address()); @@ -1842,6 +1844,7 @@ bool simple_wallet::add_custom_asset_id(const std::vector &args) if (!args.size() || args.size() > 1) { fail_msg_writer() << "invalid arguments count: " << args.size() << ", expected 1"; + return true; } crypto::public_key asset_id = currency::null_pkey; if (!epee::string_tools::parse_tpod_from_hex_string(args[0], asset_id)) @@ -1877,6 +1880,7 @@ bool simple_wallet::generate_ionic_swap_proposal(const std::vector if (args.size() != 2) { fail_msg_writer() << "invalid arguments count: " << args.size() << ", expected 1"; + return true; } view::ionic_swap_proposal_info proposal_info = AUTO_VAL_INIT(proposal_info); @@ -1884,6 +1888,7 @@ bool simple_wallet::generate_ionic_swap_proposal(const std::vector if (!r) { fail_msg_writer() << "Failed to load json file with asset specification: " << args[0]; + return true; } currency::account_public_address destination_addr = AUTO_VAL_INIT(destination_addr); currency::payment_id_t integrated_payment_id; @@ -1921,6 +1926,7 @@ bool simple_wallet::get_ionic_swap_proposal_info(const std::vector if (args.size() != 1) { fail_msg_writer() << "invalid arguments count: " << args.size() << ", expected 1"; + return true; } std::string raw_proposal; @@ -1953,6 +1959,7 @@ bool simple_wallet::accept_ionic_swap_proposal(const std::vector &a if (args.size() != 1) { fail_msg_writer() << "invalid arguments count: " << args.size() << ", expected 1"; + return true; } std::string raw_proposal; @@ -1983,6 +1990,7 @@ bool simple_wallet::remove_custom_asset_id(const std::vector &args) if (!args.size() || args.size() > 1) { fail_msg_writer() << "invalid arguments count: " << args.size() << ", expected 1"; + return true; } crypto::public_key asset_id = currency::null_pkey; if (!epee::string_tools::parse_tpod_from_hex_string(args[0], asset_id)) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index a80daf50..5d1ca212 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -6712,6 +6712,10 @@ void wallet2::transfer(construct_tx_param& ctp, check_and_throw_if_self_directed_tx_with_payment_id_requested(ctp); + bool asset_operation_requested = count_type_in_variant_container(ctp.extra) != 0; + bool dont_have_zero_asset_ids_in_destinations = std::count_if(ctp.dsts.begin(), ctp.dsts.end(), [](const tx_destination_entry& de) { return de.asset_id == null_pkey; }) == 0; + WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(asset_operation_requested || dont_have_zero_asset_ids_in_destinations, "zero asset id is used errounesly (no asset operation was requested)"); + if (ctp.crypt_address.spend_public_key == currency::null_pkey) { ctp.crypt_address = currency::get_crypt_address_from_destinations(m_account.get_keys(), ctp.dsts);