36 lines
1.6 KiB
Diff
36 lines
1.6 KiB
Diff
# UNDF: UNDF-2026-000000266
|
||
From: agent-blackops <blackops@unturf.com>
|
||
Date: Thu, 26 Mar 2026 00:00:00 +0000
|
||
Subject: [PATCH] cop/style/redundant_self: replace @allowed_send_nodes Array with identity Set
|
||
|
||
CWE-407: Algorithmic complexity via O(S) linear scan in RedundantSelf.
|
||
@allowed_send_nodes was initialised as a plain Array (`[]`) in the
|
||
constructor. The `allowed_send_node?` predicate calls
|
||
`@allowed_send_nodes.include?(node)`, which is O(S) where S is the
|
||
number of allowed send nodes accumulated so far. `on_send` calls
|
||
`allowed_send_node?` for every send node in the file, making total cost
|
||
O(sends × allowed_nodes).
|
||
|
||
Fix: initialise as `Set.new.compare_by_identity`. Node objects are
|
||
compared by identity throughout RuboCop internals; `compare_by_identity`
|
||
makes the Set use object_id for hashing, so `include?` is O(1). The
|
||
`allow_self` method uses `<<` to append — unchanged, works on Set.
|
||
|
||
Defect-Id: rubocop-0002
|
||
Severity: LOW
|
||
CWE: CWE-407 (Inefficient Algorithmic Complexity)
|
||
---
|
||
lib/rubocop/cop/style/redundant_self.rb | 2 +-
|
||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||
|
||
diff --git a/lib/rubocop/cop/style/redundant_self.rb b/lib/rubocop/cop/style/redundant_self.rb
|
||
index xxxxxxx..yyyyyyy 100644
|
||
--- a/lib/rubocop/cop/style/redundant_self.rb
|
||
+++ b/lib/rubocop/cop/style/redundant_self.rb
|
||
@@ -59,7 +59,7 @@ module RuboCop
|
||
def initialize(config = nil, options = nil)
|
||
super
|
||
- @allowed_send_nodes = []
|
||
+ @allowed_send_nodes = Set.new.compare_by_identity # CWE-407 fix: O(1) identity set
|
||
@local_variables_scopes = Hash.new { |hash, key| hash[key] = [] }.compare_by_identity
|
||
end
|