Skip to content

Commit 6a61cef

Browse files
author
Jamie C. Driver
committed
consistency psbt: use local variable when walking outputs
1 parent 25adf2c commit 6a61cef

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

main/process/sign_psbt.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,11 @@ static void validate_any_change_outputs(const char* network, struct wally_psbt*
467467

468468
// Check each output in turn
469469
for (size_t index = 0; index < psbt->num_outputs; ++index) {
470+
output_info_t* const outinfo = output_info + index;
470471
JADE_LOGD("Considering output %u for change", index);
471472

472473
// By default, assume not a validated or change output, and so user must verify
473-
JADE_ASSERT(!(output_info[index].flags & (OUTPUT_FLAG_VALIDATED | OUTPUT_FLAG_CHANGE)));
474+
JADE_ASSERT(!(outinfo->flags & (OUTPUT_FLAG_VALIDATED | OUTPUT_FLAG_CHANGE)));
474475

475476
// Find the first key belonging to this signer
476477
if (!key_iter_output_begin_public(psbt, index, &iter)) {
@@ -526,19 +527,19 @@ static void validate_any_change_outputs(const char* network, struct wally_psbt*
526527
JADE_LOGI("Output %u singlesig %s path/script validated", index, is_change ? "change" : "receive");
527528

528529
// Set appropriate flags
529-
output_info[index].flags |= OUTPUT_FLAG_VALIDATED;
530+
outinfo->flags |= OUTPUT_FLAG_VALIDATED;
530531
if (is_change) {
531-
output_info[index].flags |= OUTPUT_FLAG_CHANGE;
532+
outinfo->flags |= OUTPUT_FLAG_CHANGE;
532533
}
533534

534535
// Check the path is as expected
535536
if (!wallet_is_expected_singlesig_path(network, script_variant, is_change, path, path_len)) {
536537
// Not our standard change path - add warning
537538
char path_str[MAX_PATH_STR_LEN(MAX_PATH_LEN)];
538539
const bool have_path_str = wallet_bip32_path_as_str(path, path_len, path_str, sizeof(path_str));
539-
const int ret = snprintf(output_info[index].message, sizeof(output_info[index].message),
540-
"Unusual receive path: %s", have_path_str ? path_str : "too long");
541-
JADE_ASSERT(ret > 0 && ret < sizeof(output_info[index].message));
540+
const int ret = snprintf(outinfo->message, sizeof(outinfo->message), "Unusual receive path: %s",
541+
have_path_str ? path_str : "too long");
542+
JADE_ASSERT(ret > 0 && ret < sizeof(outinfo->message));
542543
}
543544
} else if (signing_flags == (PSBT_SIGNING_GREEN_MULTISIG | PSBT_SIGNING_MULTISIG_CHANGE_ABANDONED)) {
544545
// Signed only Green multisig inputs, only consider similar outputs
@@ -560,7 +561,7 @@ static void validate_any_change_outputs(const char* network, struct wally_psbt*
560561
JADE_LOGI("Output %u green-multisig path/script validated", index);
561562

562563
// Set appropriate flags - note Green wallet-output is always assumed to be change
563-
output_info[index].flags |= (OUTPUT_FLAG_VALIDATED | OUTPUT_FLAG_CHANGE);
564+
outinfo->flags |= (OUTPUT_FLAG_VALIDATED | OUTPUT_FLAG_CHANGE);
564565

565566
} else if (signing_flags == (PSBT_SIGNING_MULTISIG | PSBT_SIGNING_SINGLE_MULTISIG_RECORD)) {
566567
// Generic multisig or descriptor
@@ -590,19 +591,19 @@ static void validate_any_change_outputs(const char* network, struct wally_psbt*
590591
wallet_name);
591592

592593
// Set appropriate flags
593-
output_info[index].flags |= OUTPUT_FLAG_VALIDATED;
594+
outinfo->flags |= OUTPUT_FLAG_VALIDATED;
594595
if (is_change) {
595-
output_info[index].flags |= OUTPUT_FLAG_CHANGE;
596+
outinfo->flags |= OUTPUT_FLAG_CHANGE;
596597
}
597598

598599
// Check path tail looks as expected
599600
if (!wallet_is_expected_multisig_path(iter.key_index, is_change, &path[path_tail_start], path_tail_len)) {
600601
// Not our standard change path - add warning
601602
char path_str[MAX_PATH_STR_LEN(MAX_PATH_LEN)];
602603
const bool have_path_str = wallet_bip32_path_as_str(path, path_len, path_str, sizeof(path_str));
603-
const int ret = snprintf(output_info[index].message, sizeof(output_info[index].message),
604-
"Unusual change path suffix: %s", have_path_str ? path_str : "too long");
605-
JADE_ASSERT(ret > 0 && ret < sizeof(output_info[index].message));
604+
const int ret = snprintf(outinfo->message, sizeof(outinfo->message), "Unusual change path suffix: %s",
605+
have_path_str ? path_str : "too long");
606+
JADE_ASSERT(ret > 0 && ret < sizeof(outinfo->message));
606607
}
607608
} else {
608609
// Skip if we did not sign *only* multisig inputs for a single multisig record

0 commit comments

Comments
 (0)