From ac633a4c2beb9e2f5ae160b7f0f325e7846fc953 Mon Sep 17 00:00:00 2001 From: xtruan Date: Mon, 17 Jul 2023 23:19:32 -0600 Subject: [PATCH] fix: potential buff overflow, new version scheme, check size in CI --- .github/workflows/build.yml | 2 ++ application.fam | 4 +++- flipbip.h | 2 +- helpers/flipbip_file.c | 16 +++++++++++----- helpers/flipbip_file.h | 7 ++++++- views/flipbip_scene_1.c | 2 +- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4a8b2f4..683d162 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,3 +28,5 @@ jobs: run: ./fbt COMPACT=1 DEBUG=0 faps - name: Check FlipBIP Built run: test -f build/f7-firmware-C/.extapps/flipbip.fap + - name: Check FlipBIP Size + run: ls -l --block-size=K build/f7-firmware-C/.extapps/flipbip.fap diff --git a/application.fam b/application.fam index e8c660a..e0def35 100644 --- a/application.fam +++ b/application.fam @@ -10,13 +10,15 @@ App( order=10, fap_icon="flipbip_10px.png", fap_icon_assets="icons", + fap_icon_assets_symbol="flipbip", fap_private_libs=[ Lib( name="crypto", ), ], fap_category="Misc", - fap_description="Crypto toolkit for Flipper", fap_author="Struan Clark (xtruan)", fap_weburl="https://github.com/xtruan/FlipBIP", + fap_version=(1, 10), + fap_description="Crypto toolkit for Flipper", ) diff --git a/flipbip.h b/flipbip.h index 5278070..017ec65 100644 --- a/flipbip.h +++ b/flipbip.h @@ -15,7 +15,7 @@ #include "views/flipbip_startscreen.h" #include "views/flipbip_scene_1.h" -#define FLIPBIP_VERSION "v1.0.0" +#define FLIPBIP_VERSION "v1.10.0" #define COIN_BTC 0 #define COIN_DOGE 3 diff --git a/helpers/flipbip_file.c b/helpers/flipbip_file.c index 3b61b6b..addc063 100644 --- a/helpers/flipbip_file.c +++ b/helpers/flipbip_file.c @@ -33,7 +33,11 @@ const char* FILE_HSTR = "fb01"; const char* FILE_K1 = "fb0131d5cf688221c109163908ebe51debb46227c6cc8b37641910833222772a" "baefe6d9ceb651842260e0d1e05e3b90d15e7d5ffaaabc0207bf200a117793a2"; -bool flipbip_load_file(char* settings, const FlipBipFile file_type, const char* file_name) { +bool flipbip_load_file( + char* settings, + size_t slen, + const FlipBipFile file_type, + const char* file_name) { bool ret = false; const char* path; if(file_type == FlipBipFileKey) { @@ -53,10 +57,12 @@ bool flipbip_load_file(char* settings, const FlipBipFile file_type, const char* File* settings_file = storage_file_alloc(fs_api); if(storage_file_open(settings_file, path, FSAM_READ, FSOM_OPEN_EXISTING)) { char chr; - int i = 0; + size_t i = 0; while((storage_file_read(settings_file, &chr, 1) == 1) && !storage_file_eof(settings_file) && !isspace(chr)) { - settings[i] = chr; + if(i < slen) { + settings[i] = chr; + } i++; } ret = true; @@ -194,7 +200,7 @@ bool flipbip_load_file_secure(char* settings) { memzero(data, dlen); // load k2 from file - if(!flipbip_load_file(data, FlipBipFileKey, NULL)) return false; + if(!flipbip_load_file(data, dlen, FlipBipFileKey, NULL)) return false; // check header if(data[0] != FILE_HSTR[0] || data[1] != FILE_HSTR[1] || data[2] != FILE_HSTR[2] || @@ -220,7 +226,7 @@ bool flipbip_load_file_secure(char* settings) { data -= FILE_HLEN; // load data from file - if(!flipbip_load_file(data, FlipBipFileDat, NULL)) return false; + if(!flipbip_load_file(data, dlen, FlipBipFileDat, NULL)) return false; // check header if(data[0] != FILE_HSTR[0] || data[1] != FILE_HSTR[1] || data[2] != FILE_HSTR[2] || diff --git a/helpers/flipbip_file.h b/helpers/flipbip_file.h index c19f70d..3ef76dd 100644 --- a/helpers/flipbip_file.h +++ b/helpers/flipbip_file.h @@ -1,4 +1,5 @@ #include +#include typedef enum { FlipBipFileDat, @@ -7,7 +8,11 @@ typedef enum { } FlipBipFile; bool flipbip_has_file(const FlipBipFile file_type, const char* file_name, const bool remove); -bool flipbip_load_file(char* settings, const FlipBipFile file_type, const char* file_name); +bool flipbip_load_file( + char* settings, + size_t slen, + const FlipBipFile file_type, + const char* file_name); bool flipbip_save_file( const char* settings, const FlipBipFile file_type, diff --git a/views/flipbip_scene_1.c b/views/flipbip_scene_1.c index d4ca076..b7403d0 100644 --- a/views/flipbip_scene_1.c +++ b/views/flipbip_scene_1.c @@ -312,7 +312,7 @@ void flipbip_scene_1_draw(Canvas* canvas, FlipBipScene1Model* model) { canvas_draw_str(canvas, 2, 10, TEXT_LOADING); canvas_draw_str(canvas, 7, 30, s_derivation_text); canvas_draw_icon(canvas, 86, 22, &I_Keychain_39x36); - if (s_warn_insecure) { + if(s_warn_insecure) { canvas_set_font(canvas, FontSecondary); canvas_draw_str(canvas, 2, 50, WARN_INSECURE_TEXT_1); canvas_draw_str(canvas, 2, 60, WARN_INSECURE_TEXT_2);