From 7e2d6222eeea6cfd4f51b10b781f0e8efbd64c37 Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Mon, 21 Sep 2020 21:05:05 +0200 Subject: [PATCH] Add sanity checks in ESP32 native functions --- esp3d/src/include/version.h | 2 +- .../modules/filesystem/sd/sd_native_esp32.cpp | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/esp3d/src/include/version.h b/esp3d/src/include/version.h index f207043c..f706888d 100644 --- a/esp3d/src/include/version.h +++ b/esp3d/src/include/version.h @@ -22,7 +22,7 @@ #define _VERSION_ESP3D_H //version and sources location -#define FW_VERSION "3.0.0.a54" +#define FW_VERSION "3.0.0.a55" #define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0" #endif //_VERSION_ESP3D_H diff --git a/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp b/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp index 0b4b1d9b..b770c538 100644 --- a/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp @@ -142,13 +142,17 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode) bool ESP_SD::exists(const char* path) { bool res = false; + String p = path; //root should always be there if started - if (strcmp(path, "/") == 0) { + if (p == "/") { return _started; } - res = SD.exists(path); + if (p.endsWith("/")) { + p.remove( p.length() - 1,1); + } + res = SD.exists(p); if (!res) { - ESP_SDFile root = ESP_SD::open(path, ESP_FILE_READ); + ESP_SDFile root = ESP_SD::open(p.c_str(), ESP_FILE_READ); if (root) { res = root.isDirectory(); } @@ -163,7 +167,11 @@ bool ESP_SD::remove(const char *path) bool ESP_SD::mkdir(const char *path) { - return SD.mkdir(path); + String p = path; + if (p.endsWith("/")) { + p.remove( p.length() - 1,1); + } + return SD.mkdir(p.c_str()); } bool ESP_SD::rmdir(const char *path) @@ -174,6 +182,9 @@ bool ESP_SD::rmdir(const char *path) bool res = true; GenLinkedList pathlist; String p = path; + if (p.endsWith("/")) { + p.remove( p.length() - 1,1); + } pathlist.push(p); while (pathlist.count() > 0) { File dir = SD.open(pathlist.getLast().c_str());