Skip to content

Commit

Permalink
PicoPass: Fix name buffer size issues (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Dec 13, 2023
1 parent c8d2411 commit 8a135f2
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions picopass_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PicopassDevice* picopass_device_alloc() {
void picopass_device_set_name(PicopassDevice* dev, const char* name) {
furi_assert(dev);

strlcpy(dev->dev_name, name, PICOPASS_DEV_NAME_MAX_LEN);
strlcpy(dev->dev_name, name, sizeof(dev->dev_name));
}

// For use with Seader's virtual card processing.
Expand Down Expand Up @@ -343,7 +343,7 @@ bool picopass_file_select(PicopassDevice* dev) {
FuriString* filename;
filename = furi_string_alloc();
path_extract_filename(dev->load_path, filename, true);
strncpy(dev->dev_name, furi_string_get_cstr(filename), PICOPASS_DEV_NAME_MAX_LEN);
strlcpy(dev->dev_name, furi_string_get_cstr(filename), sizeof(dev->dev_name));
res = picopass_device_load_data(dev, dev->load_path, true);
if(res) {
picopass_device_set_name(dev, dev->dev_name);
Expand Down
4 changes: 2 additions & 2 deletions picopass_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#endif
#define LOCLASS_MACS_TO_COLLECT (LOCLASS_NUM_CSNS * LOCLASS_NUM_PER_CSN)

#define PICOPASS_DEV_NAME_MAX_LEN 22
#define PICOPASS_DEV_NAME_MAX_LEN 129
#define PICOPASS_READER_DATA_MAX_SIZE 64
#define PICOPASS_MAX_APP_LIMIT 32

Expand Down Expand Up @@ -119,7 +119,7 @@ typedef struct {
Storage* storage;
DialogsApp* dialogs;
PicopassDeviceData dev_data;
char dev_name[PICOPASS_DEV_NAME_MAX_LEN + 1];
char dev_name[PICOPASS_DEV_NAME_MAX_LEN];
FuriString* load_path;
PicopassDeviceSaveFormat format;
PicopassLoadingCallback loading_cb;
Expand Down
4 changes: 2 additions & 2 deletions picopass_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "protocol/picopass_poller.h"
#include "protocol/picopass_listener.h"

#define PICOPASS_TEXT_STORE_SIZE 128
#define PICOPASS_TEXT_STORE_SIZE 129

#define PICOPASS_ICLASS_ELITE_DICT_FLIPPER_NAME APP_ASSETS_PATH("iclass_elite_dict.txt")
#define PICOPASS_ICLASS_STANDARD_DICT_FLIPPER_NAME APP_ASSETS_PATH("iclass_standard_dict.txt")
Expand Down Expand Up @@ -90,7 +90,7 @@ struct Picopass {
PicopassListener* listener;
NfcDict* dict;

char text_store[PICOPASS_TEXT_STORE_SIZE + 1];
char text_store[PICOPASS_TEXT_STORE_SIZE];
FuriString* text_box_store;
uint8_t byte_input_store[PICOPASS_BLOCK_LEN];

Expand Down
2 changes: 1 addition & 1 deletion scenes/picopass_scene_delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void picopass_scene_delete_on_enter(void* context) {
Picopass* picopass = context;

// Setup Custom Widget view
char temp_str[64];
char temp_str[141];
snprintf(temp_str, sizeof(temp_str), "\e#Delete %s?\e#", picopass->dev->dev_name);
widget_add_text_box_element(
picopass->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, temp_str, false);
Expand Down
2 changes: 1 addition & 1 deletion scenes/picopass_scene_save_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void picopass_scene_save_name_on_enter(void* context) {
picopass_scene_save_name_text_input_callback,
picopass,
picopass->text_store,
PICOPASS_DEV_NAME_MAX_LEN,
sizeof(picopass->text_store),
dev_name_empty);

FuriString* folder_path;
Expand Down

0 comments on commit 8a135f2

Please sign in to comment.