signing: copy content of root HDNode in signing_init

Instead of just storing a pointer, store the content, in case they
later get overwritten.
pull/25/head
Jochen Hoenicke 6 years ago committed by Pavol Rusnak
parent 9226589604
commit 5cbeb970c9
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -28,11 +28,12 @@
#include "secp256k1.h"
#include "gettext.h"
#include "messages.pb.h"
#include "memzero.h"
static uint32_t inputs_count;
static uint32_t outputs_count;
static const CoinInfo *coin;
static const HDNode *root;
static CONFIDENTIAL HDNode root;
static CONFIDENTIAL HDNode node;
static bool signing = false;
enum {
@ -457,7 +458,7 @@ bool compile_input_script_sig(TxInputType *tinput)
return false;
}
}
memcpy(&node, root, sizeof(HDNode));
memcpy(&node, &root, sizeof(HDNode));
if (hdnode_private_ckd_cached(&node, tinput->address_n, tinput->address_n_count, NULL) == 0) {
// Failed to derive private key
return false;
@ -478,7 +479,7 @@ void signing_init(const SignTx *msg, const CoinInfo *_coin, const HDNode *_root)
inputs_count = msg->inputs_count;
outputs_count = msg->outputs_count;
coin = _coin;
root = _root;
memcpy(&root, _root, sizeof(HDNode));
version = msg->version;
lock_time = msg->lock_time;
expiry = msg->expiry;
@ -659,7 +660,7 @@ static bool signing_check_output(TxOutputType *txoutput) {
return false;
}
spending += txoutput->amount;
int co = compile_output(coin, root, txoutput, &bin_output, !is_change);
int co = compile_output(coin, &root, txoutput, &bin_output, !is_change);
if (!is_change) {
layoutProgress(_("Signing transaction"), progress);
}
@ -1207,7 +1208,7 @@ void signing_txack(TransactionType *tx)
return;
case STAGE_REQUEST_4_OUTPUT:
progress = 500 + ((signatures * progress_step + (inputs_count + idx2) * progress_meta_step) >> PROGRESS_PRECISION);
if (compile_output(coin, root, tx->outputs, &bin_output, false) <= 0) {
if (compile_output(coin, &root, tx->outputs, &bin_output, false) <= 0) {
fsm_sendFailure(FailureType_Failure_ProcessError, _("Failed to compile output"));
signing_abort();
return;
@ -1330,7 +1331,7 @@ void signing_txack(TransactionType *tx)
return;
case STAGE_REQUEST_5_OUTPUT:
if (compile_output(coin, root, tx->outputs, &bin_output,false) <= 0) {
if (compile_output(coin, &root, tx->outputs, &bin_output,false) <= 0) {
fsm_sendFailure(FailureType_Failure_ProcessError, _("Failed to compile output"));
signing_abort();
return;
@ -1428,4 +1429,6 @@ void signing_abort(void)
layoutHome();
signing = false;
}
memzero(&root, sizeof(root));
memzero(&node, sizeof(node));
}

Loading…
Cancel
Save