From 5997f231395a25dc52b2965ed5a5c5cedaa18589 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 16 Feb 2022 01:38:44 +0100 Subject: [PATCH] flasher: ask confirmation if fw mismatch, fix segfault on abort --- client/src/flash.c | 9 +++++++-- client/src/proxmark3.c | 6 ++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/client/src/flash.c b/client/src/flash.c index 6bd525ce0..076b4859e 100644 --- a/client/src/flash.c +++ b/client/src/flash.c @@ -322,8 +322,13 @@ int flash_load(flash_file_t *ctx) { if (strlen(g_version_information.armsrc) == 9) { if (strncmp(vi->armsrc, g_version_information.armsrc, 9) != 0) { PrintAndLogEx(WARNING, _RED_("ARM firmware does not match the source at the time the client was compiled")); - PrintAndLogEx(WARNING, "Make sure to flash a correct and up-to-date version"); -// TODO: prompt user to continue or abort + PrintAndLogEx(INFO, "Make sure to flash a correct and up-to-date version"); + PrintAndLogEx(NORMAL, "Do you want to flash the current image? (yes/no)"); + char answer[10]; + if ((fgets (answer, sizeof(answer), stdin) == NULL) || (strncmp(answer, "yes", 3) != 0)) { + res = PM3_EOPABORTED; + goto fail; + } } } } diff --git a/client/src/proxmark3.c b/client/src/proxmark3.c index 1fce51cd8..2a3d3befa 100644 --- a/client/src/proxmark3.c +++ b/client/src/proxmark3.c @@ -637,7 +637,7 @@ static int flash_pm3(char *serial_port_name, uint8_t num_files, char *filenames[ for (int i = 0 ; i < num_files; ++i) { ret = flash_load(&files[i]); if (ret != PM3_SUCCESS) { - goto finish; + goto finish2; } PrintAndLogEx(NORMAL, ""); } @@ -679,7 +679,7 @@ static int flash_pm3(char *serial_port_name, uint8_t num_files, char *filenames[ finish: if (ret != PM3_SUCCESS) - PrintAndLogEx(INFO, "The flashing procedure failed, follow the suggested steps!"); + PrintAndLogEx(WARNING, "The flashing procedure failed, follow the suggested steps!"); ret = flash_stop_flashing(); CloseProxmark(g_session.current_device); finish2: @@ -688,6 +688,8 @@ finish2: } if (ret == PM3_SUCCESS) PrintAndLogEx(SUCCESS, _CYAN_("All done")); + else if (ret == PM3_EOPABORTED) + PrintAndLogEx(FAILED, "Aborted by user"); else PrintAndLogEx(ERR, "Aborted on error"); PrintAndLogEx(INFO, "\nHave a nice day!");