From bd8fd9e37dc12a761f5a00cf5815b5bd589b8347 Mon Sep 17 00:00:00 2001 From: ALTracer Date: Mon, 13 May 2024 20:21:22 +0300 Subject: [PATCH] target: Replace remaining sprintf calls with snprintf * These cases in efm32, sam3x, stm32l0 store a string into bounded priv_storage * Pass its size as second argument, as done everywhere else --- src/target/efm32.c | 3 ++- src/target/sam3x.c | 6 +++--- src/target/stm32l0.c | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/target/efm32.c b/src/target/efm32.c index 891e2be7c8f..0f594bc2e7b 100644 --- a/src/target/efm32.c +++ b/src/target/efm32.c @@ -960,7 +960,8 @@ bool efm32_aap_probe(adiv5_access_port_s *ap) DEBUG_INFO("EFM32: AAP STATUS=%08" PRIx32 "\n", adiv5_ap_read(ap, AAP_STATUS)); efm32_aap_priv_s *priv_storage = calloc(1, sizeof(*priv_storage)); - sprintf(priv_storage->aap_driver_string, "EFM32 Authentication Access Port rev.%hu", aap_revision); + snprintf(priv_storage->aap_driver_string, sizeof(priv_storage->aap_driver_string), + "EFM32 Authentication Access Port rev.%hu", aap_revision); t->driver = priv_storage->aap_driver_string; t->regs_size = 0; diff --git a/src/target/sam3x.c b/src/target/sam3x.c index a97db636499..68cfa1169cf 100644 --- a/src/target/sam3x.c +++ b/src/target/sam3x.c @@ -407,9 +407,9 @@ bool samx7x_probe(target_s *t) sam_add_flash(t, SAMX7X_EEFC_BASE, 0x00400000, priv_storage->descr.flash_size); target_add_commands(t, sam_cmd_list, "SAMX7X"); - sprintf(priv_storage->sam_variant_string, "SAM%c%02d%c%d%c", priv_storage->descr.product_code, - priv_storage->descr.product_id, priv_storage->descr.pins, priv_storage->descr.density, - priv_storage->descr.revision); + snprintf(priv_storage->sam_variant_string, sizeof(priv_storage->sam_variant_string), "SAM%c%02d%c%d%c", + priv_storage->descr.product_code, priv_storage->descr.product_id, priv_storage->descr.pins, + priv_storage->descr.density, priv_storage->descr.revision); t->driver = priv_storage->sam_variant_string; return true; diff --git a/src/target/stm32l0.c b/src/target/stm32l0.c index 81d65d7a7f5..b1ca5db5d5c 100644 --- a/src/target/stm32l0.c +++ b/src/target/stm32l0.c @@ -258,7 +258,8 @@ bool stm32l0_probe(target_s *const target) const uint32_t nvm = stm32lx_nvm_phys(target); const bool protected = (target_mem32_read32(target, STM32Lx_NVM_OPTR(nvm)) & STM32Lx_NVM_OPTR_RDPROT_M) != STM32Lx_NVM_OPTR_RDPROT_0; - sprintf(priv_storage->stm32l_variant, "%s%s", target->driver, protected ? " (protected)" : ""); + snprintf(priv_storage->stm32l_variant, sizeof(priv_storage->stm32l_variant), "%s%s", target->driver, + protected ? " (protected)" : ""); target->driver = priv_storage->stm32l_variant; if (protected) {