Fix longFilename NULL pointer dereference
This commit is contained in:
parent
37b56e09a3
commit
1e88c9f673
1 changed files with 32 additions and 30 deletions
|
|
@ -1125,6 +1125,7 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
|
||||||
// Return if normal file or subdirectory
|
// Return if normal file or subdirectory
|
||||||
if (DIR_IS_FILE_OR_SUBDIR(dir)) {
|
if (DIR_IS_FILE_OR_SUBDIR(dir)) {
|
||||||
#if ENABLED(UTF_FILENAME_SUPPORT)
|
#if ENABLED(UTF_FILENAME_SUPPORT)
|
||||||
|
if (longFilename) {
|
||||||
// Convert filename from utf-16 to utf-8 as Marlin expects
|
// Convert filename from utf-16 to utf-8 as Marlin expects
|
||||||
#if LONG_FILENAME_CHARSIZE > 2
|
#if LONG_FILENAME_CHARSIZE > 2
|
||||||
// Add warning for developers for currently not supported 3-byte cases (Conversion series of 2-byte
|
// Add warning for developers for currently not supported 3-byte cases (Conversion series of 2-byte
|
||||||
|
|
@ -1132,6 +1133,7 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
|
||||||
#error "Currently filename re-encoding is done in-place. It may break the remaining chars to use 3-byte codepoints."
|
#error "Currently filename re-encoding is done in-place. It may break the remaining chars to use 3-byte codepoints."
|
||||||
#endif
|
#endif
|
||||||
uint16_t currentPos = 0;
|
uint16_t currentPos = 0;
|
||||||
|
|
||||||
LOOP_L_N(i, (LONG_FILENAME_LENGTH / 2)) {
|
LOOP_L_N(i, (LONG_FILENAME_LENGTH / 2)) {
|
||||||
uint16_t idx = i * 2; // This is fixed as FAT LFN always contain UTF-16LE encoding
|
uint16_t idx = i * 2; // This is fixed as FAT LFN always contain UTF-16LE encoding
|
||||||
|
|
||||||
|
|
@ -1156,10 +1158,10 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
|
||||||
|
|
||||||
if (0 == utf16_ch) break; // End of filename
|
if (0 == utf16_ch) break; // End of filename
|
||||||
}
|
}
|
||||||
return currentPos;
|
n = currentPos;
|
||||||
#else
|
}
|
||||||
return n;
|
|
||||||
#endif
|
#endif
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue