Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit ae321fb

Browse files
committed
Mfw NULL pointer dereference (fix IFTTT)
1 parent 8a5cef0 commit ae321fb

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

applications/external/ifttt/ifttt_virtual_button.c

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ void save_settings_file(FlipperFormat* file, Settings* settings) {
3838
Settings* load_settings() {
3939
Settings* settings = malloc(sizeof(Settings));
4040

41+
settings->save_ssid = "";
42+
settings->save_password = "";
43+
settings->save_key = "";
44+
settings->save_event = "";
45+
4146
Storage* storage = furi_record_open(RECORD_STORAGE);
4247
FlipperFormat* file = flipper_format_file_alloc(storage);
4348

@@ -53,29 +58,14 @@ Settings* load_settings() {
5358
text_event_value = furi_string_alloc();
5459

5560
if(storage_common_stat(storage, CONFIG_FILE_PATH, NULL) != FSE_OK) {
56-
if(!flipper_format_file_open_new(file, CONFIG_FILE_PATH)) {
57-
flipper_format_file_close(file);
58-
} else {
59-
settings->save_ssid = malloc(1);
60-
settings->save_password = malloc(1);
61-
settings->save_key = malloc(1);
62-
settings->save_event = malloc(1);
63-
64-
settings->save_ssid[0] = '\0';
65-
settings->save_password[0] = '\0';
66-
settings->save_key[0] = '\0';
67-
settings->save_event[0] = '\0';
68-
61+
if(flipper_format_file_open_new(file, CONFIG_FILE_PATH)) {
6962
save_settings_file(file, settings);
70-
flipper_format_file_close(file);
7163
}
64+
flipper_format_file_close(file);
7265
} else {
73-
if(!flipper_format_file_open_existing(file, CONFIG_FILE_PATH)) {
74-
flipper_format_file_close(file);
75-
} else {
66+
if(flipper_format_file_open_existing(file, CONFIG_FILE_PATH)) {
7667
uint32_t value;
77-
if(!flipper_format_read_header(file, string_value, &value)) {
78-
} else {
68+
if(flipper_format_read_header(file, string_value, &value)) {
7969
if(flipper_format_read_string(file, CONF_SSID, text_ssid_value)) {
8070
settings->save_ssid = malloc(furi_string_size(text_ssid_value) + 1);
8171
strcpy(settings->save_ssid, furi_string_get_cstr(text_ssid_value));
@@ -93,8 +83,8 @@ Settings* load_settings() {
9383
strcpy(settings->save_event, furi_string_get_cstr(text_event_value));
9484
}
9585
}
96-
flipper_format_file_close(file);
9786
}
87+
flipper_format_file_close(file);
9888
}
9989

10090
furi_string_free(text_ssid_value);
@@ -248,4 +238,4 @@ int32_t ifttt_virtual_button_app(void* p) {
248238
view_dispatcher_run(app->view_dispatcher);
249239
ifttt_virtual_button_app_free(app);
250240
return 0;
251-
}
241+
}

0 commit comments

Comments
 (0)