From 263df08179b45216c63808e3653e50abd49bbc09 Mon Sep 17 00:00:00 2001 From: Arthur Bonnaudet Date: Fri, 15 Nov 2024 11:33:58 +0100 Subject: [PATCH] NBGL Nano: Check onActionCallback validity In nbgl_step actionCallback, `onActionCallback` was called without being checked, leading to crash if the callback is NULL. This commit adds the relevant checks. --- lib_nbgl/src/nbgl_step.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib_nbgl/src/nbgl_step.c b/lib_nbgl/src/nbgl_step.c index e5a9d6f6..69bb1328 100644 --- a/lib_nbgl/src/nbgl_step.c +++ b/lib_nbgl/src/nbgl_step.c @@ -309,7 +309,9 @@ static void actionCallback(nbgl_layout_t *layout, nbgl_buttonEvent_t event) } else if ((ctx->textContext.pos == LAST_STEP) || (ctx->textContext.pos == NEITHER_FIRST_NOR_LAST_STEP)) { - ctx->textContext.onActionCallback((nbgl_step_t) ctx, event); + if (ctx->textContext.onActionCallback != NULL) { + ctx->textContext.onActionCallback((nbgl_step_t) ctx, event); + } } } else if (event == BUTTON_RIGHT_PRESSED) { @@ -319,11 +321,15 @@ static void actionCallback(nbgl_layout_t *layout, nbgl_buttonEvent_t event) } else if ((ctx->textContext.pos == FIRST_STEP) || (ctx->textContext.pos == NEITHER_FIRST_NOR_LAST_STEP)) { - ctx->textContext.onActionCallback((nbgl_step_t) ctx, event); + if (ctx->textContext.onActionCallback != NULL) { + ctx->textContext.onActionCallback((nbgl_step_t) ctx, event); + } } } else if (event == BUTTON_BOTH_PRESSED) { - ctx->textContext.onActionCallback((nbgl_step_t) ctx, event); + if (ctx->textContext.onActionCallback != NULL) { + ctx->textContext.onActionCallback((nbgl_step_t) ctx, event); + } } }