Skip to content

Commit a42ae8c

Browse files
authored
Merge pull request #16 from blooo-io/fix/audit-fix
fix: handle non-checked returned value
2 parents 5eb7ff5 + b71f82f commit a42ae8c

File tree

6 files changed

+34
-12
lines changed

6 files changed

+34
-12
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ PATH_SLIP21_APP_LOAD_PARAMS = "LEDGER-Wallet policy"
4747
# Application version
4848
APPVERSION_M = 1
4949
APPVERSION_N = 0
50-
APPVERSION_P = 2
50+
APPVERSION_P = 3
5151
APPVERSION_SUFFIX = # if not empty, appended at the end. Do not add a dash.
5252

5353
ifeq ($(APPVERSION_SUFFIX),)

src/handler/withdraw.c

+33-11
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ static bool display_data_content_and_confirm(dispatcher_context_t* dc,
213213
if (address_type == -1 || redeemer_address_len == -1) {
214214
PRINTF("Error: Address type or address length is invalid\n");
215215
SEND_SW(dc, SW_INCORRECT_DATA);
216-
ui_post_processing_confirm_withdraw(dc, false);
216+
if (!ui_post_processing_confirm_withdraw(dc, false)) {
217+
PRINTF("Error in ui_post_processing_confirm_withdraw");
218+
}
217219
return false;
218220
}
219221
if (!check_address(bip32_path,
@@ -222,7 +224,9 @@ static bool display_data_content_and_confirm(dispatcher_context_t* dc,
222224
redeemer_address_len,
223225
address_type)) {
224226
SEND_SW(dc, SW_INCORRECT_DATA);
225-
ui_post_processing_confirm_withdraw(dc, false);
227+
if (!ui_post_processing_confirm_withdraw(dc, false)) {
228+
PRINTF("Error in ui_post_processing_confirm_withdraw");
229+
}
226230
return false;
227231
}
228232

@@ -298,7 +302,9 @@ void fetch_and_add_chunk_to_hash(dispatcher_context_t* dc,
298302
CHUNK_SIZE_IN_BYTES);
299303
if (current_chunk_len < 0) {
300304
SAFE_SEND_SW(dc, SW_WRONG_DATA_LENGTH);
301-
ui_post_processing_confirm_withdraw(dc, false);
305+
if (!ui_post_processing_confirm_withdraw(dc, false)) {
306+
PRINTF("Error in ui_post_processing_confirm_withdraw");
307+
}
302308
return;
303309
}
304310
size_t field_buffer_size = FIELD_SIZE;
@@ -351,7 +357,9 @@ void fetch_and_add_chunk_to_buffer(dispatcher_context_t* dc,
351357
CHUNK_SIZE_IN_BYTES);
352358
if (current_chunk_len < 0) {
353359
SAFE_SEND_SW(dc, SW_WRONG_DATA_LENGTH);
354-
ui_post_processing_confirm_withdraw(dc, false);
360+
if (!ui_post_processing_confirm_withdraw(dc, false)) {
361+
PRINTF("Error in ui_post_processing_confirm_withdraw");
362+
}
355363
return;
356364
}
357365
size_t input_buffer_size;
@@ -583,7 +591,9 @@ uint32_t sign_tx_hash(dispatcher_context_t* dc,
583591
if (sig_len < 0) {
584592
// unexpected error when signing
585593
SAFE_SEND_SW(dc, SW_BAD_STATE);
586-
ui_post_processing_confirm_message(dc, false);
594+
if (!ui_post_processing_confirm_withdraw(dc, false)) {
595+
PRINTF("Error in ui_post_processing_confirm_withdraw");
596+
}
587597
return -1;
588598
}
589599
return info;
@@ -635,13 +645,17 @@ void handler_withdraw(dispatcher_context_t* dc, uint8_t protocol_version) {
635645
!buffer_read_varint(&dc->read_buffer, &n_chunks) ||
636646
!buffer_read_bytes(&dc->read_buffer, data_merkle_root, 32)) {
637647
SEND_SW(dc, SW_WRONG_DATA_LENGTH);
638-
ui_post_processing_confirm_withdraw(dc, false);
648+
if (!ui_post_processing_confirm_withdraw(dc, false)) {
649+
PRINTF("Error in ui_post_processing_confirm_withdraw");
650+
}
639651
return;
640652
}
641653

642654
if (bip32_path_len > MAX_BIP32_PATH_STEPS) {
643655
SEND_SW(dc, SW_INCORRECT_DATA);
644-
ui_post_processing_confirm_withdraw(dc, false);
656+
if (!ui_post_processing_confirm_withdraw(dc, false)) {
657+
PRINTF("Error in ui_post_processing_confirm_withdraw");
658+
}
645659
return;
646660
}
647661

@@ -657,7 +671,9 @@ void handler_withdraw(dispatcher_context_t* dc, uint8_t protocol_version) {
657671
bip32_path,
658672
bip32_path_len)) {
659673
SEND_SW(dc, SW_DENY);
660-
ui_post_processing_confirm_withdraw(dc, false);
674+
if (!ui_post_processing_confirm_withdraw(dc, false)) {
675+
PRINTF("Error in ui_post_processing_confirm_withdraw");
676+
}
661677
return;
662678
}
663679

@@ -670,7 +686,9 @@ void handler_withdraw(dispatcher_context_t* dc, uint8_t protocol_version) {
670686
char tx_hash_str[65];
671687
if (!format_hex(tx_hash, KECCAK_256_HASH_SIZE, tx_hash_str, sizeof(tx_hash_str))) {
672688
SEND_SW(dc, SW_BAD_STATE);
673-
ui_post_processing_confirm_message(dc, false);
689+
if (!ui_post_processing_confirm_withdraw(dc, false)) {
690+
PRINTF("Error in ui_post_processing_confirm_withdraw");
691+
}
674692
return;
675693
};
676694

@@ -689,7 +707,9 @@ void handler_withdraw(dispatcher_context_t* dc, uint8_t protocol_version) {
689707

690708
if (r_length > 33 || s_length > 33) {
691709
SEND_SW(dc, SW_BAD_STATE); // can never happen
692-
ui_post_processing_confirm_message(dc, false);
710+
if (!ui_post_processing_confirm_withdraw(dc, false)) {
711+
PRINTF("Error in ui_post_processing_confirm_withdraw");
712+
}
693713
return;
694714
}
695715

@@ -705,6 +725,8 @@ void handler_withdraw(dispatcher_context_t* dc, uint8_t protocol_version) {
705725
result[0] = 27 + 4 + ((info & CX_ECCINFO_PARITY_ODD) ? 1 : 0);
706726

707727
SEND_RESPONSE(dc, result, sizeof(result), SW_OK);
708-
ui_post_processing_confirm_message(dc, true);
728+
if (!ui_post_processing_confirm_withdraw(dc, true)) {
729+
PRINTF("Error in ui_post_processing_confirm_withdraw");
730+
}
709731
return;
710732
}
27 Bytes
Loading
0 Bytes
Loading
0 Bytes
Loading
9 Bytes
Loading

0 commit comments

Comments
 (0)