From ca2884548a44a4350e1bf8f77ed3a57f25c0e32d Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Sun, 23 Apr 2023 14:02:55 +0100 Subject: [PATCH] Sanitize name changer input --- .../scenes/xtreme_app_scene_misc_rename.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_rename.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_rename.c index a5f5dd8c5..30684da65 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_rename.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_rename.c @@ -12,12 +12,28 @@ static void xtreme_app_scene_misc_rename_text_input_callback(void* context) { view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk); } +static bool xtreme_app_scene_misc_rename_validator(const char* text, FuriString* error, void* context) { + UNUSED(context); + + for(; *text; ++text) { + const char c = *text; + if((c < '0' || c > '9') && (c < 'A' || c > 'Z') && (c < 'a' || c > 'z')) { + furi_string_printf(error, "Please only\nenter letters\nand numbers!"); + return false; + } + } + + return true; +} + void xtreme_app_scene_misc_rename_on_enter(void* context) { XtremeApp* app = context; TextInput* text_input = app->text_input; text_input_set_header_text(text_input, "Leave empty for default"); + text_input_set_validator(text_input, xtreme_app_scene_misc_rename_validator, NULL); + text_input_set_result_callback( text_input, xtreme_app_scene_misc_rename_text_input_callback,