From 4fd76524c931a814749ab0f40c830bfd146491d3 Mon Sep 17 00:00:00 2001 From: WillyJL <49810075+Willy-JL@users.noreply.github.com> Date: Fri, 6 Sep 2024 11:33:17 +0200 Subject: [PATCH] Desktop: Sanity check PIN length for good measure (#3879) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Desktop: Sanity check PIN length for good measure * Desktop: replace hardcoded values with macros in desktop_view_pin_input.c Co-authored-by: あく --- applications/services/desktop/helpers/pin_code.c | 3 ++- applications/services/desktop/helpers/pin_code.h | 1 + applications/services/desktop/views/desktop_view_pin_input.c | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/applications/services/desktop/helpers/pin_code.c b/applications/services/desktop/helpers/pin_code.c index d1a37ed24..82e117a53 100644 --- a/applications/services/desktop/helpers/pin_code.c +++ b/applications/services/desktop/helpers/pin_code.c @@ -58,7 +58,8 @@ static uint32_t desktop_pin_code_pack(const DesktopPinCode* pin_code) { } bool desktop_pin_code_is_set(void) { - return furi_hal_rtc_get_pin_value() >> DESKTOP_PIN_CODE_LENGTH_OFFSET; + uint8_t length = furi_hal_rtc_get_pin_value() >> DESKTOP_PIN_CODE_LENGTH_OFFSET; + return length >= DESKTOP_PIN_CODE_MIN_LEN && length <= DESKTOP_PIN_CODE_MAX_LEN; } void desktop_pin_code_set(const DesktopPinCode* pin_code) { diff --git a/applications/services/desktop/helpers/pin_code.h b/applications/services/desktop/helpers/pin_code.h index 848c915b6..d0695794b 100644 --- a/applications/services/desktop/helpers/pin_code.h +++ b/applications/services/desktop/helpers/pin_code.h @@ -3,6 +3,7 @@ #include #include +#define DESKTOP_PIN_CODE_MIN_LEN (4) #define DESKTOP_PIN_CODE_MAX_LEN (10) typedef struct { diff --git a/applications/services/desktop/views/desktop_view_pin_input.c b/applications/services/desktop/views/desktop_view_pin_input.c index c89a143c8..3c18f166c 100644 --- a/applications/services/desktop/views/desktop_view_pin_input.c +++ b/applications/services/desktop/views/desktop_view_pin_input.c @@ -13,7 +13,7 @@ #define DEFAULT_PIN_X 64 #define DEFAULT_PIN_Y 32 -#define MIN_PIN_LENGTH 4 +#define MIN_PIN_LENGTH DESKTOP_PIN_CODE_MIN_LEN #define MAX_PIN_LENGTH DESKTOP_PIN_CODE_MAX_LEN struct DesktopViewPinInput { @@ -103,7 +103,7 @@ static void desktop_view_pin_input_draw_cells(Canvas* canvas, DesktopViewPinInpu furi_assert(canvas); furi_assert(model); - uint8_t draw_pin_size = MAX(4, model->pin.length + 1); + uint8_t draw_pin_size = MAX(MIN_PIN_LENGTH, model->pin.length + 1); if(model->locked_input || (model->pin.length == MAX_PIN_LENGTH)) { draw_pin_size = model->pin.length; }