From 0d47c814ab359a2cdb20a8d4fdee329e4e8d0117 Mon Sep 17 00:00:00 2001 From: neithanmo Date: Mon, 9 Dec 2024 16:46:18 +0100 Subject: [PATCH] Check for ui buffer size first --- app/src/plan/output_plan.c | 18 +++++++++--------- app/src/plan/spend_plan.c | 16 +++++++++------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/app/src/plan/output_plan.c b/app/src/plan/output_plan.c index 3543f19..42249e4 100644 --- a/app/src/plan/output_plan.c +++ b/app/src/plan/output_plan.c @@ -79,16 +79,16 @@ parser_error_t output_getItem(const parser_context_t *ctx, const output_plan_t * } - char bufferUI[OUTPUT_DISPLAY_MAX_LEN] = {0}; - switch ( displayIdx ) { - case 0: - snprintf(outKey, outKeyLen, "Action"); - CHECK_ERROR(output_printValue(ctx, output, bufferUI, sizeof(bufferUI))); - pageString(outVal, outValLen, bufferUI, pageIdx, pageCount); - break; - default: - return parser_no_data; + if (displayIdx != 0) { + return parser_no_data; } + + char bufferUI[OUTPUT_DISPLAY_MAX_LEN] = {0}; + + snprintf(outKey, outKeyLen, "Action"); + CHECK_ERROR(output_printValue(ctx, output, bufferUI, sizeof(bufferUI))); + pageString(outVal, outValLen, bufferUI, pageIdx, pageCount); + return parser_ok; } diff --git a/app/src/plan/spend_plan.c b/app/src/plan/spend_plan.c index eb3847e..66a8baa 100644 --- a/app/src/plan/spend_plan.c +++ b/app/src/plan/spend_plan.c @@ -109,19 +109,21 @@ parser_error_t spend_getItem(const parser_context_t *ctx, const spend_plan_t *sp uint8_t *pageCount) { parser_error_t err = parser_no_data; + if (spend == NULL || outKey == NULL || outVal == NULL || outKeyLen == 0 || outValLen == 0) { return err; } + if (displayIdx != 0) { + return err; + } + char bufferUI[SPEND_DISPLAY_MAX_LEN] = {0}; - if (displayIdx == 0) { - snprintf(outKey, outKeyLen, "Action"); - CHECK_ERROR(spend_printValue(ctx, spend, bufferUI, sizeof(bufferUI))); - pageString(outVal, outValLen, bufferUI, pageIdx, pageCount); - return parser_ok; - } + snprintf(outKey, outKeyLen, "Action"); + CHECK_ERROR(spend_printValue(ctx, spend, bufferUI, sizeof(bufferUI))); + pageString(outVal, outValLen, bufferUI, pageIdx, pageCount); - return parser_no_data; + return parser_ok; }