From 3bc392f5920a40c8b2b47127702eb01e07cb2096 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 3 Jun 2018 13:32:40 +0200 Subject: [PATCH] Prevent a buffer overflow in cardreader --- Marlin/cardreader.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Marlin/cardreader.cpp b/Marlin/cardreader.cpp index 72eaa26940..146f6ca035 100644 --- a/Marlin/cardreader.cpp +++ b/Marlin/cardreader.cpp @@ -582,9 +582,8 @@ const char* CardReader::diveToFile(SdFile*& curDir, const char * const path, con while (dirname_start) { char * const dirname_end = strchr(dirname_start, '/'); if (dirname_end <= dirname_start) break; - - char dosSubdirname[FILENAME_LENGTH]; const uint8_t len = dirname_end - dirname_start; + char dosSubdirname[len + 1]; strncpy(dosSubdirname, dirname_start, len); dosSubdirname[len] = 0;