2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-08 17:04:55 +00:00

CStringExtras: Prevent potential out of bounds reads with CompareCaseInsensitive

The strcasecmp and _stricmp functions expect the passed in strings to
be null-terminated, however we we're also exposing a std::string_view
overload for that function. std::string_view instances aren't required
to be null-terminated, so this makes the interface a little unsafe.

We can use std::lexicographical_compare() to provide the same behavior
and also properly handle the case of non-null-terminated strings.
This commit is contained in:
Lioncash
2019-09-14 11:14:51 -04:00
parent 002ca71104
commit 0d2b2f45a8
5 changed files with 30 additions and 18 deletions

View File

@@ -9,7 +9,7 @@ CResLoader::CResLoader() { x48_curPak = x18_pakLoadedList.end(); }
const std::vector<CAssetId>* CResLoader::GetTagListForFile(std::string_view name) const {
const std::string namePak = std::string(name).append(".upak");
for (const std::unique_ptr<CPakFile>& pak : x18_pakLoadedList) {
if (!CStringExtras::CompareCaseInsensitive(namePak, pak->x18_path)) {
if (CStringExtras::CompareCaseInsensitive(namePak, pak->x18_path)) {
return &pak->GetDepList();
}
}
@@ -117,7 +117,7 @@ std::unique_ptr<u8[]> CResLoader::LoadNewResourcePartSync(const urde::SObjectTag
void CResLoader::GetTagListForFile(const char* pakName, std::vector<SObjectTag>& out) const {
std::string path = std::string(pakName) + ".upak";
for (const std::unique_ptr<CPakFile>& file : x18_pakLoadedList) {
if (!CStringExtras::CompareCaseInsensitive(file->GetPath(), path)) {
if (CStringExtras::CompareCaseInsensitive(file->GetPath(), path)) {
auto& depList = file->GetDepList();
out.reserve(depList.size());
for (const auto& dep : depList) {