Skip to content

Commit

Permalink
clean: replace last Throw by app exit
Browse files Browse the repository at this point in the history
  • Loading branch information
sgliner-ledger committed Oct 24, 2023
1 parent fc54782 commit e27be0e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
16 changes: 8 additions & 8 deletions src/monero_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void monero_io_clear(void) {

void monero_io_hole(unsigned int sz) {
if ((G_monero_vstate.io_length + sz) > MONERO_IO_BUFFER_LENGTH) {
THROW(ERROR_IO_FULL);
send_error_and_kill_app(ERROR_IO_FULL);
}
memmove(G_monero_vstate.io_buffer + G_monero_vstate.io_offset + sz,
G_monero_vstate.io_buffer + G_monero_vstate.io_offset,
Expand All @@ -76,7 +76,7 @@ void monero_io_hole(unsigned int sz) {

void monero_io_insert(unsigned char const* buff, unsigned int len) {
if (!buff) {
THROW(SW_WRONG_DATA);
send_error_and_kill_app(ERROR_IO_FULL);
}
monero_io_hole(len);
memcpy(G_monero_vstate.io_buffer + G_monero_vstate.io_offset, buff, len);
Expand All @@ -85,11 +85,11 @@ void monero_io_insert(unsigned char const* buff, unsigned int len) {

void monero_io_insert_hmac_for(unsigned char* buffer, int len, int type) {
if (!buffer) {
THROW(SW_WRONG_DATA);
send_error_and_kill_app(ERROR_IO_FULL);
}
// for now, only 32bytes block are allowed
if (len != 32) {
THROW(SW_WRONG_DATA);
send_error_and_kill_app(ERROR_IO_FULL);
}

unsigned char hmac[32 + 1 + 4];
Expand All @@ -113,12 +113,12 @@ void monero_io_insert_hmac_for(unsigned char* buffer, int len, int type) {

void monero_io_insert_encrypt(unsigned char* buffer, size_t len, int type) {
if (!buffer) {
THROW(SW_WRONG_DATA);
send_error_and_kill_app(ERROR_IO_FULL);
}

// for now, only 32bytes block are allowed
if (len != 32) {
THROW(SW_WRONG_DATA);
send_error_and_kill_app(ERROR_IO_FULL);
}

monero_io_hole(len);
Expand Down Expand Up @@ -205,7 +205,7 @@ int monero_io_fetch_available(void) {
}
void monero_io_assert_available(int sz) {
if ((G_monero_vstate.io_length - G_monero_vstate.io_offset) < sz) {
THROW(SW_WRONG_LENGTH + (sz & 0xFF));
send_error_and_kill_app(ERROR_IO_FULL);
}
}

Expand All @@ -217,7 +217,7 @@ void monero_io_skip(int len) {
int monero_io_fetch(unsigned char* buffer, int len) {
monero_io_assert_available(len);
if (!buffer) {
THROW(SW_WRONG_DATA);
send_error_and_kill_app(ERROR_IO_FULL);
}
memcpy(buffer, G_monero_vstate.io_buffer + G_monero_vstate.io_offset, len);
G_monero_vstate.io_offset += len;
Expand Down
12 changes: 8 additions & 4 deletions src/monero_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
/* ----------------------------------------------------------------------- */
void __attribute__((noreturn)) app_exit(void);

void send_error_and_kill_app(int sw) {
monero_io_insert_u16(sw);
monero_io_do(IO_RETURN_AFTER_TX);
memset(&G_monero_vstate, 0, sizeof(G_monero_vstate));
app_exit();
}

void app_main(void) {
unsigned int io_flags;
unsigned int error;
Expand All @@ -63,10 +70,7 @@ void app_main(void) {
io_flags = 0;
}
else {
monero_io_insert_u16(sw);
monero_io_do(IO_RETURN_AFTER_TX);
memset(&G_monero_vstate, 0, sizeof(G_monero_vstate));
app_exit();
send_error_and_kill_app(sw);
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/monero_ux_nano.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#define ACCEPT 0xACCE
#define REJECT ~ACCEPT

void __attribute__((noreturn)) app_exit(void);
void ui_menu_main_display();


Expand Down Expand Up @@ -663,6 +664,11 @@ void ui_menu_pubaddr_display(unsigned int value) {
ui_menu_any_pubaddr_display(value, G_monero_vstate.A, G_monero_vstate.B, 0, NULL);
}

static void exit(void) {
memset(&G_monero_vstate, 0, sizeof(G_monero_vstate));
app_exit();
}

#undef ADDR_TYPE
#undef ADDR_MAJOR
#undef ADDR_MINOR
Expand All @@ -682,7 +688,7 @@ UX_STEP_CB(ux_menu_main_2_step, pb,

UX_STEP_CB(ux_menu_main_3_step, pb, ui_menu_about_display(), {&C_icon_certificate, "About"});

UX_STEP_CB(ux_menu_main_4_step, pb, os_sched_exit(0), {&C_icon_dashboard_x, "Quit app"});
UX_STEP_CB(ux_menu_main_4_step, pb, exit(), {&C_icon_dashboard_x, "Quit app"});

UX_FLOW(ux_flow_main, &ux_menu_main_1_step, &ux_menu_main_2_step, &ux_menu_main_3_step,
&ux_menu_main_4_step);
Expand Down
3 changes: 2 additions & 1 deletion src/monero_ux_stax_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ static void update_account(void) {
}

static void exit(void) {
os_sched_exit(-1);
memset(&G_monero_vstate, 0, sizeof(G_monero_vstate));
app_exit();
}

static bool settings_navigation_cb(uint8_t page, nbgl_pageContent_t* content) {
Expand Down

0 comments on commit e27be0e

Please sign in to comment.