26 lines
1.2 KiB
Diff
26 lines
1.2 KiB
Diff
# UNDF: UNDF-2026-000000898
|
|
--- a/src/dos/drives.h
|
|
+++ b/src/dos/drives.h
|
|
@@ -1350 +1350 @@
|
|
- std::vector<std::string> DOSnames_cache; //Also set is probably better.
|
|
+ std::unordered_set<std::string, CaseInsensitiveHash, CaseInsensitiveEqual> DOSnames_set;
|
|
--- a/src/dos/drive_overlay.cpp
|
|
+++ b/src/dos/drive_overlay.cpp
|
|
@@ -730,6 +730,5 @@
|
|
void Overlay_Drive::add_DOSname_to_cache(const char* name) {
|
|
- for (std::vector<std::string>::const_iterator itc = DOSnames_cache.begin(); itc != DOSnames_cache.end(); ++itc){
|
|
- if (!strcasecmp((*itc).c_str(), name)) return;
|
|
- }
|
|
- DOSnames_cache.push_back(name);
|
|
+ std::string key(name);
|
|
+ // O(1) amortized insert with case-insensitive dedup instead of O(N) linear scan
|
|
+ DOSnames_set.insert(key);
|
|
}
|
|
#
|
|
# CWE-407: Overlay_Drive::add_DOSname_to_cache scans DOSnames_cache vector
|
|
# with strcasecmp for every insertion — O(N) per insert, O(N^2) total for
|
|
# N cached names. The code itself comments "Also set is probably better."
|
|
# Fix: replace std::vector with std::unordered_set using case-insensitive
|
|
# hash/equal functors.
|
|
# Severity: MEDIUM — triggers during overlay directory enumeration, scales
|
|
# with number of files in overlaid directories.
|