mirror of
https://github.com/dwhinham/mt32-pi.git
synced 2026-07-08 17:56:50 +00:00
Fix unterminated config file buffer
This commit is contained in:
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- A bug in the config file reader (unterminated string) could cause the last entry in the file to be read as a corrupted value if the file ended without a newline.
|
||||
|
||||
## [0.11.0] - 2021-12-12
|
||||
|
||||
### Added
|
||||
|
||||
@@ -89,8 +89,9 @@ bool CConfig::Initialize(const char* pPath)
|
||||
return false;
|
||||
}
|
||||
|
||||
// +1 byte for null terminator
|
||||
const UINT nSize = f_size(&File);
|
||||
char Buffer[nSize];
|
||||
char Buffer[nSize + 1];
|
||||
UINT nRead;
|
||||
|
||||
if (f_read(&File, Buffer, nSize, &nRead) != FR_OK)
|
||||
@@ -100,6 +101,9 @@ bool CConfig::Initialize(const char* pPath)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ensure null-terminated
|
||||
Buffer[nRead] = '\0';
|
||||
|
||||
const int nResult = ini_parse_string(Buffer, INIHandler, this);
|
||||
if (nResult > 0)
|
||||
CLogger::Get()->Write(ConfigName, LogWarning, "Config parse error on line %d", nResult);
|
||||
@@ -162,6 +166,8 @@ int CConfig::INIHandler(void* pUser, const char* pSection, const char* pName, co
|
||||
CConfig* const pConfig = static_cast<CConfig*>(pUser);
|
||||
size_t nFXProfileIndex;
|
||||
|
||||
//CLogger::Get()->Write(ConfigName, LogDebug, "'%s', '%s', '%s'", pSection, pName, pValue);
|
||||
|
||||
// Automatically generate ParseOption() calls from macro definition file
|
||||
#define BEGIN_SECTION(SECTION) \
|
||||
if (!strcmp(#SECTION, pSection)) \
|
||||
|
||||
Reference in New Issue
Block a user