mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-09 04:27:42 +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:
@@ -18,9 +18,11 @@ CPakFile::~CPakFile() {
|
||||
}
|
||||
|
||||
const SObjectTag* CPakFile::GetResIdByName(std::string_view name) const {
|
||||
for (const std::pair<std::string, SObjectTag>& p : x54_nameList)
|
||||
if (!CStringExtras::CompareCaseInsensitive(p.first.c_str(), name))
|
||||
for (const std::pair<std::string, SObjectTag>& p : x54_nameList) {
|
||||
if (CStringExtras::CompareCaseInsensitive(p.first, name)) {
|
||||
return &p.second;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user