From 23abe60705a7b1040d177478a3ff1403d1fe0ef4 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 19 Jan 2019 13:02:47 +0000 Subject: check load_t_from_json return values --- src/cryptonote_basic/miner.cpp | 3 ++- src/wallet/message_transporter.cpp | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/cryptonote_basic/miner.cpp b/src/cryptonote_basic/miner.cpp index d29a3dcd6..3a51c6ea4 100644 --- a/src/cryptonote_basic/miner.cpp +++ b/src/cryptonote_basic/miner.cpp @@ -305,7 +305,8 @@ namespace cryptonote } m_config_folder_path = boost::filesystem::path(command_line::get_arg(vm, arg_extra_messages)).parent_path().string(); m_config = AUTO_VAL_INIT(m_config); - epee::serialization::load_t_from_json_file(m_config, m_config_folder_path + "/" + MINER_CONFIG_FILE_NAME); + const std::string filename = m_config_folder_path + "/" + MINER_CONFIG_FILE_NAME; + CHECK_AND_ASSERT_MES(epee::serialization::load_t_from_json_file(m_config, filename), false, "Failed to load data from " << filename); MINFO("Loaded " << m_extra_messages.size() << " extra messages, current index " << m_config.current_extra_message_index); } diff --git a/src/wallet/message_transporter.cpp b/src/wallet/message_transporter.cpp index 19bfa074d..2f8188a3c 100644 --- a/src/wallet/message_transporter.cpp +++ b/src/wallet/message_transporter.cpp @@ -118,7 +118,11 @@ bool message_transporter::receive_messages(const std::vector &desti std::string json = get_str_between_tags(answer, "", ""); bitmessage_rpc::inbox_messages_response bitmessage_res; - epee::serialization::load_t_from_json(bitmessage_res, json); + if (!epee::serialization::load_t_from_json(bitmessage_res, json)) + { + MERROR("Failed to deserialize messages"); + return true; + } size_t size = bitmessage_res.inboxMessages.size(); messages.clear(); @@ -140,8 +144,10 @@ bool message_transporter::receive_messages(const std::vector &desti std::string message_body = epee::string_encoding::base64_decode(message_info.message); // Second Base64-decoding: The MMS uses Base64 to hide non-textual data in its JSON from Bitmessage json = epee::string_encoding::base64_decode(message_body); - epee::serialization::load_t_from_json(message, json); - is_mms_message = true; + if (!epee::serialization::load_t_from_json(message, json)) + MERROR("Failed to deserialize message"); + else + is_mms_message = true; } catch(const std::exception& e) { -- cgit v1.2.3