From 3295579e054761fa6a08f60f552a17637491b44d Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 13 Jul 2023 18:36:11 +0200 Subject: [PATCH] jsonToPixels robustness avoid string overflow when constructing filename --- wled00/FX_2Dfcn.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index 6dfc77b3..0556935c 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -605,11 +605,12 @@ void Segment::drawArc(uint16_t x0, uint16_t y0, uint16_t radius, uint32_t color, //WLEDMM for artifx bool Segment::jsonToPixels(char * name, uint8_t fileNr) { - char fileName[32]; + if (!isActive()) return true; // segment not active, nothing to do + char fileName[32] = { '\0' }; //WLEDMM: als support segment name ledmaps - bool isFile = false;; + bool isFile = false; // strcpy_P(fileName, PSTR("/mario")); - sprintf(fileName, "/%s%d.json", name, fileNr); //WLEDMM: trick to not include 0 in ledmap.json + snprintf(fileName, sizeof(fileName), "/%s%d.json", name, fileNr); //WLEDMM: trick to not include 0 in ledmap.json // strcat(fileName, ".json"); isFile = WLED_FS.exists(fileName);