From c4cfa87a42c58546335fdd06a98bb1df7ff3632e Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 1 Jun 2024 23:23:24 +0200 Subject: [PATCH] drivers/nutdrv_qx_blazer-common.c: blazer_process_command() for "test.battery.start" might vary by applicable formatting strings [#2450] Signed-off-by: Jim Klimov --- drivers/nutdrv_qx_blazer-common.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/nutdrv_qx_blazer-common.c b/drivers/nutdrv_qx_blazer-common.c index cd4ea4a0ff..4736dc00c8 100644 --- a/drivers/nutdrv_qx_blazer-common.c +++ b/drivers/nutdrv_qx_blazer-common.c @@ -329,7 +329,26 @@ int blazer_process_command(item_t *item, char *value, const size_t valuelen) delay = delay / 60; - snprintf(value, valuelen, item->command, delay); + /* In various mapping tables, "%02d" is prevalent; actual + * value is range-checked above to fit into a typical int + */ + if (validate_formatting_string(item->command, "%d", -1) >= 0) { + /* The most likely case, should not cause debug-log + * noise for most end-users when missing the check */ + snprintf_dynamic(value, valuelen, item->command, "%d", (int)delay); + } else { + if (validate_formatting_string(item->command, "", -1) >= 0) { + /* A few mappings seem to just request the test + * without parameters, so the second check is + * for that eventuality + */ + snprintf(value, valuelen, "%s", item->command); + } else { + /* Finally try the actual long int (complaining + * with default verbosity==1 if a bad fit) */ + snprintf_dynamic(value, valuelen, item->command, "%ld", delay); + } + } } else {