From ae1471ab39c0cf611e717a2e6875192c1d4a87b5 Mon Sep 17 00:00:00 2001 From: Bill Greiman Date: Sat, 23 Dec 2017 05:44:26 -0800 Subject: [PATCH] Add invalid cluster error checks --- library.properties | 2 +- src/FatLib/FatVolume.cpp | 10 ++++++++-- src/SdFat.h | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/library.properties b/library.properties index fb482ae8..4ea2a083 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SdFat -version=1.0.3 +version=1.0.4 author=Bill Greiman maintainer=Bill Greiman sentence=FAT16/FAT32 file system for SD cards. diff --git a/src/FatLib/FatVolume.cpp b/src/FatLib/FatVolume.cpp index 82c77730..ace0862c 100644 --- a/src/FatLib/FatVolume.cpp +++ b/src/FatLib/FatVolume.cpp @@ -200,7 +200,10 @@ int8_t FatVolume::fatGet(uint32_t cluster, uint32_t* value) { cache_t* pc; // error if reserved cluster of beyond FAT - DBG_HALT_IF(cluster < 2 || cluster > m_lastCluster); + if (cluster < 2 || cluster > m_lastCluster) { + DBG_FAIL_MACRO; + goto fail; + } if (fatType() == 32) { lba = m_fatStartBlock + (cluster >> 7); @@ -266,7 +269,10 @@ bool FatVolume::fatPut(uint32_t cluster, uint32_t value) { cache_t* pc; // error if reserved cluster of beyond FAT - DBG_HALT_IF(cluster < 2 || cluster > m_lastCluster); + if (cluster < 2 || cluster > m_lastCluster) { + DBG_FAIL_MACRO; + goto fail; + } if (fatType() == 32) { lba = m_fatStartBlock + (cluster >> 7); diff --git a/src/SdFat.h b/src/SdFat.h index 00969cfb..3ba6d7fd 100644 --- a/src/SdFat.h +++ b/src/SdFat.h @@ -34,7 +34,7 @@ #include "SdCard/SdioCard.h" //------------------------------------------------------------------------------ /** SdFat version */ -#define SD_FAT_VERSION "1.0.3" +#define SD_FAT_VERSION "1.0.4" //============================================================================== /** * \class SdBaseFile