From ae321fb5f4c616d3965546926b1b4b446eef8d86 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 2 May 2023 20:40:23 +0100 Subject: [PATCH] Mfw NULL pointer dereference (fix IFTTT) --- .../external/ifttt/ifttt_virtual_button.c | 32 +++++++------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/applications/external/ifttt/ifttt_virtual_button.c b/applications/external/ifttt/ifttt_virtual_button.c index e23b8715d..d518a1109 100644 --- a/applications/external/ifttt/ifttt_virtual_button.c +++ b/applications/external/ifttt/ifttt_virtual_button.c @@ -38,6 +38,11 @@ void save_settings_file(FlipperFormat* file, Settings* settings) { Settings* load_settings() { Settings* settings = malloc(sizeof(Settings)); + settings->save_ssid = ""; + settings->save_password = ""; + settings->save_key = ""; + settings->save_event = ""; + Storage* storage = furi_record_open(RECORD_STORAGE); FlipperFormat* file = flipper_format_file_alloc(storage); @@ -53,29 +58,14 @@ Settings* load_settings() { text_event_value = furi_string_alloc(); if(storage_common_stat(storage, CONFIG_FILE_PATH, NULL) != FSE_OK) { - if(!flipper_format_file_open_new(file, CONFIG_FILE_PATH)) { - flipper_format_file_close(file); - } else { - settings->save_ssid = malloc(1); - settings->save_password = malloc(1); - settings->save_key = malloc(1); - settings->save_event = malloc(1); - - settings->save_ssid[0] = '\0'; - settings->save_password[0] = '\0'; - settings->save_key[0] = '\0'; - settings->save_event[0] = '\0'; - + if(flipper_format_file_open_new(file, CONFIG_FILE_PATH)) { save_settings_file(file, settings); - flipper_format_file_close(file); } + flipper_format_file_close(file); } else { - if(!flipper_format_file_open_existing(file, CONFIG_FILE_PATH)) { - flipper_format_file_close(file); - } else { + if(flipper_format_file_open_existing(file, CONFIG_FILE_PATH)) { uint32_t value; - if(!flipper_format_read_header(file, string_value, &value)) { - } else { + if(flipper_format_read_header(file, string_value, &value)) { if(flipper_format_read_string(file, CONF_SSID, text_ssid_value)) { settings->save_ssid = malloc(furi_string_size(text_ssid_value) + 1); strcpy(settings->save_ssid, furi_string_get_cstr(text_ssid_value)); @@ -93,8 +83,8 @@ Settings* load_settings() { strcpy(settings->save_event, furi_string_get_cstr(text_event_value)); } } - flipper_format_file_close(file); } + flipper_format_file_close(file); } furi_string_free(text_ssid_value); @@ -248,4 +238,4 @@ int32_t ifttt_virtual_button_app(void* p) { view_dispatcher_run(app->view_dispatcher); ifttt_virtual_button_app_free(app); return 0; -} \ No newline at end of file +}