Skip to content

Commit eed4296

Browse files
DrZlo13skotopes
andauthored
MPU Hal (#1492)
* Furi HAL: memory protection unit * Core: prohibit NULL dereferencing, even for reads. * Applications: fix NULL dereference * Core: stack protection by MPU * MPU: stack region alignment * Apps: fix null pointer dereferences * Threads: fix non-null arg check * Desktop settings: fix null pointer dereference * Core: documented null-check hack * Fix null dereference issues * Apps: args check * Core: naming fixes * format code * Core: remove NONNULL specifier * FurHal: move MPU initialization to begining, fix enum naming Co-authored-by: あく <[email protected]>
1 parent 4a6477a commit eed4296

File tree

29 files changed

+238
-62
lines changed

29 files changed

+238
-62
lines changed

applications/archive/scenes/archive_scene_rename.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void archive_scene_rename_on_enter(void* context) {
3737
false);
3838

3939
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
40-
string_get_cstr(archive->browser->path), archive->file_extension, NULL);
40+
string_get_cstr(archive->browser->path), archive->file_extension, "");
4141
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
4242

4343
string_clear(filename);

applications/bad_usb/bad_usb_app.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ BadUsbApp* bad_usb_app_alloc(char* arg) {
2828

2929
string_init(app->file_path);
3030

31-
if(arg != NULL) {
31+
if(arg && strlen(arg)) {
3232
string_set_str(app->file_path, arg);
3333
}
3434

@@ -79,7 +79,6 @@ void bad_usb_app_free(BadUsbApp* app) {
7979
furi_assert(app);
8080

8181
// Views
82-
view_dispatcher_remove_view(app->view_dispatcher, BadUsbAppViewFileSelect);
8382
view_dispatcher_remove_view(app->view_dispatcher, BadUsbAppViewWork);
8483
bad_usb_free(app->bad_usb_view);
8584

applications/bad_usb/bad_usb_app_i.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,5 @@ struct BadUsbApp {
3838

3939
typedef enum {
4040
BadUsbAppViewError,
41-
BadUsbAppViewFileSelect,
4241
BadUsbAppViewWork,
4342
} BadUsbAppView;

applications/bt/bt_service/bt.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ static void bt_close_connection(Bt* bt) {
347347
furi_event_flag_set(bt->api_event, BT_API_UNLOCK_EVENT);
348348
}
349349

350-
int32_t bt_srv() {
350+
int32_t bt_srv(void* p) {
351+
UNUSED(p);
351352
Bt* bt = bt_alloc();
352353

353354
if(furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal) {

applications/desktop/animations/views/bubble_animation_view.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,24 @@ static void bubble_animation_activate(BubbleAnimationView* view, bool force) {
143143
furi_assert(view);
144144
bool activate = true;
145145
BubbleAnimationViewModel* model = view_get_model(view->view);
146-
if(!model->current) {
146+
if(model->current == NULL) {
147147
activate = false;
148148
} else if(model->freeze_frame) {
149149
activate = false;
150150
} else if(model->current->active_frames == 0) {
151151
activate = false;
152152
}
153153

154-
if(!force) {
155-
if((model->active_ended_at + model->current->active_cooldown * 1000) >
156-
xTaskGetTickCount()) {
157-
activate = false;
158-
} else if(model->active_shift) {
159-
activate = false;
160-
} else if(model->current_frame >= model->current->passive_frames) {
161-
activate = false;
154+
if(model->current != NULL) {
155+
if(!force) {
156+
if((model->active_ended_at + model->current->active_cooldown * 1000) >
157+
xTaskGetTickCount()) {
158+
activate = false;
159+
} else if(model->active_shift) {
160+
activate = false;
161+
} else if(model->current_frame >= model->current->passive_frames) {
162+
activate = false;
163+
}
162164
}
163165
}
164166
view_commit_model(view->view, false);
@@ -288,7 +290,10 @@ static void bubble_animation_enter(void* context) {
288290
bubble_animation_activate(view, false);
289291

290292
BubbleAnimationViewModel* model = view_get_model(view->view);
291-
uint8_t frame_rate = model->current->icon_animation.frame_rate;
293+
uint8_t frame_rate = 0;
294+
if(model->current != NULL) {
295+
frame_rate = model->current->icon_animation.frame_rate;
296+
}
292297
view_commit_model(view->view, false);
293298

294299
if(frame_rate) {

applications/desktop/desktop_settings/desktop_settings_app.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void desktop_settings_app_free(DesktopSettingsApp* app) {
9090
extern int32_t desktop_settings_app(void* p) {
9191
DesktopSettingsApp* app = desktop_settings_app_alloc();
9292
LOAD_DESKTOP_SETTINGS(&app->settings);
93-
if(!strcmp(p, DESKTOP_SETTINGS_RUN_PIN_SETUP_ARG)) {
93+
if(p && (strcmp(p, DESKTOP_SETTINGS_RUN_PIN_SETUP_ARG) == 0)) {
9494
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppScenePinSetupHowto);
9595
} else {
9696
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneStart);

applications/gui/modules/button_menu.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,19 @@ static void button_menu_process_ok(ButtonMenu* button_menu, InputType type) {
185185
return false;
186186
});
187187

188-
if(item->type == ButtonMenuItemTypeControl) {
189-
if(type == InputTypeShort) {
190-
if(item && item->callback) {
191-
item->callback(item->callback_context, item->index, type);
188+
if(item) {
189+
if(item->type == ButtonMenuItemTypeControl) {
190+
if(type == InputTypeShort) {
191+
if(item && item->callback) {
192+
item->callback(item->callback_context, item->index, type);
193+
}
192194
}
193195
}
194-
}
195-
if(item->type == ButtonMenuItemTypeCommon) {
196-
if((type == InputTypePress) || (type == InputTypeRelease)) {
197-
if(item && item->callback) {
198-
item->callback(item->callback_context, item->index, type);
196+
if(item->type == ButtonMenuItemTypeCommon) {
197+
if((type == InputTypePress) || (type == InputTypeRelease)) {
198+
if(item && item->callback) {
199+
item->callback(item->callback_context, item->index, type);
200+
}
199201
}
200202
}
201203
}

applications/gui/modules/text_input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static void text_input_backspace_cb(TextInputModel* model) {
147147

148148
static void text_input_view_draw_callback(Canvas* canvas, void* _model) {
149149
TextInputModel* model = _model;
150-
uint8_t text_length = strlen(model->text_buffer);
150+
uint8_t text_length = model->text_buffer ? strlen(model->text_buffer) : 0;
151151
uint8_t needed_string_width = canvas_width(canvas) - 8;
152152
uint8_t start_pos = 4;
153153

applications/gui/modules/validators.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
// #include <gui/view.h>
43
#include <m-string.h>
4+
#include <core/common_defines.h>
55

66
#ifdef __cplusplus
77
extern "C" {

applications/ibutton/ibutton.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ int32_t ibutton_app(void* p) {
353353
bool key_loaded = false;
354354
bool rpc_mode = false;
355355

356-
if(p) {
356+
if(p && strlen(p)) {
357357
uint32_t rpc_ctx = 0;
358358
if(sscanf(p, "RPC %lX", &rpc_ctx) == 1) {
359359
FURI_LOG_D(TAG, "Running in RPC mode");

0 commit comments

Comments
 (0)