java-topology/defects/dry/patch/dry-0002-object-unsub-hashset.patch
russell@unturf.com 068ebbd29f cpp-systems: tor CLEAN.md updated to note existing patches tor-0001/0002/0003
Scanned bitcoin/dragonfly/tor/transmission/nmap/ceph/allegro5 for additional
CWE-407 defects. All repos found CLEAN beyond previously recorded patches.
Updated tor/CLEAN.md to correctly reference existing tor-0001 through tor-0003.
2026-03-29 19:54:59 -04:00

33 lines
1.3 KiB
Diff

# UNDF: UNDF-2026-000000316
--- a/Source/Dry/Core/Object.cpp
+++ b/Source/Dry/Core/Object.cpp
@@ -269,12 +269,16 @@ void Object::UnsubscribeFromAllEventsExcept(const PODVector<StringHash>& exceptions, bool onlyUserData)
{
EventHandler* handler = eventHandlers_.First();
EventHandler* previous = nullptr;
+ // FIX dry-0002: was exceptions.Contains() — O(m) per handler — CWE-407
+ // With n handlers and m exceptions: O(n*m) total.
+ // Build a HashSet once at O(m), then each check is O(1) → O(n) total.
+ HashSet<StringHash> exceptionsSet(exceptions.Begin(), exceptions.End());
+
while (handler)
{
EventHandler* next = eventHandlers_.Next(handler);
- if ((!onlyUserData || handler->GetUserData()) && !exceptions.Contains(handler->GetEventType()))
+ if ((!onlyUserData || handler->GetUserData()) && !exceptionsSet.Contains(handler->GetEventType()))
{
if (handler->GetSender())
context_->RemoveEventReceiver(this, handler->GetSender(), handler->GetEventType());
else
context_->RemoveEventReceiver(this, handler->GetEventType());
eventHandlers_.Erase(handler, previous);
}
else
previous = handler;
handler = next;
}
}