58 lines
2.5 KiB
Diff
58 lines
2.5 KiB
Diff
# UNDF: UNDF-2026-000000032
|
|
diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx
|
|
index d2da7ec..0d785a1 100644
|
|
--- a/Source/cmComputeLinkDepends.cxx
|
|
+++ b/Source/cmComputeLinkDepends.cxx
|
|
@@ -1075,6 +1075,8 @@ void cmComputeLinkDepends::AddLinkEntries(cm::optional<size_t> depender_index,
|
|
assert(group);
|
|
dependee_index = group->first;
|
|
if (group->second) {
|
|
+ this->GroupItemSets.emplace(group->first,
|
|
+ std::unordered_set<size_t>(groupItems.begin(), groupItems.end()));
|
|
this->GroupItems.emplace(group->first, std::move(groupItems));
|
|
}
|
|
group = cm::nullopt;
|
|
@@ -1164,8 +1166,7 @@ void cmComputeLinkDepends::AddLinkEntries(cm::optional<size_t> depender_index,
|
|
if (groupFeature == currentFeature) {
|
|
continue;
|
|
}
|
|
- if (std::find(g.second.cbegin(), g.second.cend(), dependee_index) !=
|
|
- g.second.cend()) {
|
|
+ if (this->GroupItemSets.at(g.first).count(dependee_index)) {
|
|
this->CMakeInstance->IssueMessage(
|
|
MessageType::FATAL_ERROR,
|
|
cmStrCat("Impossible to link target '", this->Target->GetName(),
|
|
@@ -1360,9 +1361,8 @@ void cmComputeLinkDepends::UpdateGroupDependencies()
|
|
}
|
|
// search the item in the defined groups
|
|
for (auto const& groupItems : this->GroupItems) {
|
|
- auto pos = std::find(groupItems.second.cbegin(),
|
|
- groupItems.second.cend(), index);
|
|
- if (pos != groupItems.second.cend()) {
|
|
+ // CWE-407 fix: O(1) set lookup replaces O(n) std::find scan
|
|
+ if (this->GroupItemSets.at(groupItems.first).count(index)) {
|
|
// replace lib dependency by the group it belongs to
|
|
edge = cmGraphEdge{ groupItems.first, false, false,
|
|
cmListFileBacktrace() };
|
|
diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h
|
|
index f2162cf..b31e3b4 100644
|
|
--- a/Source/cmComputeLinkDepends.h
|
|
+++ b/Source/cmComputeLinkDepends.h
|
|
@@ -10,6 +10,8 @@
|
|
#include <queue>
|
|
#include <set>
|
|
#include <string>
|
|
+#include <unordered_map>
|
|
+#include <unordered_set>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
@@ -123,6 +125,8 @@ private:
|
|
|
|
// map storing, for each group, the list of items
|
|
std::map<size_t, std::vector<size_t>> GroupItems;
|
|
+ // CWE-407 fix: O(1) set for GroupItems membership checks (std::find was O(n))
|
|
+ std::unordered_map<size_t, std::unordered_set<size_t>> GroupItemSets;
|
|
|
|
// BFS of initial dependencies.
|
|
struct BFSEntry
|