enumerateLedmaps: prevent buffer overflow

make sure that bounds of char fileName[33] are not exceeded by sprintf.
This commit is contained in:
Frank
2023-04-14 18:33:07 +02:00
parent 5f4dd53be4
commit 10ca7c83ca
2 changed files with 5 additions and 5 deletions

View File

@@ -1319,9 +1319,9 @@ uint8_t * Segment::getAudioPalette(int pal) {
// enumerate all ledmapX.json files on FS and extract ledmap names if existing
void WS2812FX::enumerateLedmaps() {
ledMaps = 1;
for (size_t i=1; i<10; i++) {
for (int i=1; i<10; i++) {
char fileName[33];
sprintf_P(fileName, PSTR("/ledmap%d.json"), i);
snprintf_P(fileName, sizeof(fileName), PSTR("/ledmap%d.json"), i);
bool isFile = WLED_FS.exists(fileName);
#ifndef ESP8266
@@ -1364,8 +1364,8 @@ void WS2812FX::enumerateLedmaps() {
uint8_t segment_index = 0;
for (segment &seg : _segments) {
if (seg.name != nullptr && strcmp(seg.name, "") != 0) {
char fileName[32];
sprintf_P(fileName, PSTR("/lm%s.json"), seg.name);
char fileName[33];
snprintf_P(fileName, sizeof(fileName), PSTR("/lm%s.json"), seg.name);
bool isFile = WLED_FS.exists(fileName);
if (isFile) ledMaps |= 1 << (10+segment_index);
}

View File

@@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2304080
#define VERSION 2304140
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG