From beb2e4783205e612844395eb25b0de66809b703c Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Mon, 6 Jul 2015 16:05:22 -0400 Subject: [PATCH] Prevent deref of invalid optional on wallet import of malformed WIF key --- libraries/wallet/wallet.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 75f9d434..9afe63c3 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1907,7 +1907,10 @@ bool wallet_api::import_key(string account_name_or_id, string wif_key) { FC_ASSERT(!is_locked()); // backup wallet - string shorthash = detail::address_to_shorthash(wif_to_key(wif_key)->get_public_key()); + fc::optional optional_private_key = wif_to_key(wif_key); + if (!optional_private_key) + FC_THROW("Invalid private key ${key}", ("key", wif_key)); + string shorthash = detail::address_to_shorthash(optional_private_key->get_public_key()); copy_wallet_file( "before-import-key-" + shorthash ); if( my->import_key(account_name_or_id, wif_key) )