Skip to content

Commit

Permalink
fix: potential buff overflow, new version scheme, check size in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
xtruan committed Jul 18, 2023
1 parent 1375bc6 commit ac633a4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
2 changes: 1 addition & 1 deletion flipbip.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions helpers/flipbip_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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] ||
Expand All @@ -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] ||
Expand Down
7 changes: 6 additions & 1 deletion helpers/flipbip_file.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdbool.h>
#include <stddef.h>

typedef enum {
FlipBipFileDat,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion views/flipbip_scene_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ac633a4

Please sign in to comment.