From 9bb6162626c011e1828e95ab25d867ca94c4ee3e Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 5 Sep 2016 19:38:56 -0700 Subject: [PATCH] Add extra checking of memo data in hexadecimal string format. --- src/wallet/asyncrpcoperation_sendmany.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index ab905b4d..0243ec6b 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -945,10 +945,15 @@ void AsyncRPCOperation_sendmany::add_taddr_change_output_to_tx(CAmount amount) { } boost::array AsyncRPCOperation_sendmany::get_memo_from_hex_string(std::string s) { - boost::array memo = {{0x00}}; - std::vector rawMemo = ParseHex(s.c_str()); + std::vector rawMemo = ParseHex(s.c_str()); + + // If ParseHex comes across a non-hex char, it will stop but still return results so far. + size_t slen = s.length(); + if (slen % 2 !=0 || (slen>0 && rawMemo.size()!=slen/2)) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Memo must be in hexadecimal format"); + } if (rawMemo.size() > ZC_MEMO_SIZE) { throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Memo size of %d is too big, maximum allowed is %d", rawMemo.size(), ZC_MEMO_SIZE));