Fixed memory access past the end of the vector data

Log printing uses charPtr as char const *, assuming that it's a null-terminated string. But it's a vector.
Signed-off-by: Alexander Borsuk <me@alex.bio>
This commit is contained in:
Alexander Borsuk 2024-05-09 22:31:16 +02:00 committed by Alexander Borsuk
parent 6e93e5b7a5
commit 36136bde5c

View file

@ -16,6 +16,7 @@
#include "geometry/mercator.hpp"
#include "coding/file_reader.hpp"
#include "coding/file_writer.hpp"
#include "coding/internal/file_data.hpp"
#include "coding/serdes_json.hpp"
@ -1865,20 +1866,16 @@ void BookmarkManager::LoadMetadata()
return;
Metadata metadata;
std::vector<uint8_t> jsonStr;
auto const charPtr = [&jsonStr]()
{
return reinterpret_cast<char const *>(jsonStr.data());
};
std::string json;
try
{
jsonStr = base::ReadFile(metadataFilePath);
if (jsonStr.empty())
FileReader(metadataFilePath).ReadAsString(json);
if (json.empty())
return;
coding::DeserializerJson des(charPtr());
coding::DeserializerJson des(json);
des(metadata);
}
catch (FileReader::Exception const & exception)
@ -1888,8 +1885,7 @@ void BookmarkManager::LoadMetadata()
}
catch (base::Json::Exception const & exception)
{
LOG(LWARNING, ("Exception while parsing file:", metadataFilePath, "reason:", exception.what(),
"json:", charPtr()));
LOG(LWARNING, ("Exception while parsing file:", metadataFilePath, "reason:", exception.what(), "json:", json));
return;
}