diff --git a/lib/msf/core/data_store.rb b/lib/msf/core/data_store.rb index 27cd0f55fa..17027abc3c 100644 --- a/lib/msf/core/data_store.rb +++ b/lib/msf/core/data_store.rb @@ -212,6 +212,18 @@ class DataStore < Hash self end + # + # Overrides the builtin 'each' operator to avoid the following exception on Ruby 1.9.2+ + # "can't add a new key into hash during iteration" + # + def each(&block) + list = [] + self.keys.sort.each do |sidx| + list << [sidx, self[sidx]] + end + list.each(&block) + end + protected # diff --git a/lib/msf/core/module_manager.rb b/lib/msf/core/module_manager.rb index 30b2128fdb..8dfbcbf4cd 100644 --- a/lib/msf/core/module_manager.rb +++ b/lib/msf/core/module_manager.rb @@ -110,6 +110,18 @@ class ModuleSet < Hash (self[name]) ? true : false end + # + # Overrides the builtin 'each' operator to avoid the following exception on Ruby 1.9.2+ + # "can't add a new key into hash during iteration" + # + def each(&block) + list = [] + self.keys.sort.each do |sidx| + list << [sidx, self[sidx]] + end + list.each(&block) + end + # # Enumerates each module class in the set. # diff --git a/lib/msf/core/option_container.rb b/lib/msf/core/option_container.rb index 0d5def48e2..742008dded 100644 --- a/lib/msf/core/option_container.rb +++ b/lib/msf/core/option_container.rb @@ -632,6 +632,18 @@ class OptionContainer < Hash each_pair(&block) end + # + # Overrides the builtin 'each' operator to avoid the following exception on Ruby 1.9.2+ + # "can't add a new key into hash during iteration" + # + def each(&block) + list = [] + self.keys.sort.each do |sidx| + list << [sidx, self[sidx]] + end + list.each(&block) + end + # # Merges the options in this container with another option container and # returns the sorted results. diff --git a/lib/rex/job_container.rb b/lib/rex/job_container.rb index 5d2e5ba017..c6c067d231 100644 --- a/lib/rex/job_container.rb +++ b/lib/rex/job_container.rb @@ -177,6 +177,18 @@ class JobContainer < Hash self.delete(inst.jid.to_s) end + # + # Overrides the builtin 'each' operator to avoid the following exception on Ruby 1.9.2+ + # "can't add a new key into hash during iteration" + # + def each(&block) + list = [] + self.keys.sort.each do |sidx| + list << [sidx, self[sidx]] + end + list.each(&block) + end + protected attr_accessor :job_id_pool # :nodoc: diff --git a/lib/rex/proto/http/header.rb b/lib/rex/proto/http/header.rb index b604066f23..a347519566 100644 --- a/lib/rex/proto/http/header.rb +++ b/lib/rex/proto/http/header.rb @@ -141,6 +141,18 @@ class Packet::Header < Hash self.dcase_hash.clear end + # + # Overrides the builtin 'each' operator to avoid the following exception on Ruby 1.9.2+ + # "can't add a new key into hash during iteration" + # + def each(&block) + list = [] + self.keys.sort.each do |sidx| + list << [sidx, self[sidx]] + end + list.each(&block) + end + # # The raw command string associated with the header which will vary between # requests and responses. diff --git a/lib/rex/service_manager.rb b/lib/rex/service_manager.rb index 2b95d2bdc0..8beabd655c 100644 --- a/lib/rex/service_manager.rb +++ b/lib/rex/service_manager.rb @@ -127,6 +127,18 @@ class ServiceManager < Hash return false end + # + # Overrides the builtin 'each' operator to avoid the following exception on Ruby 1.9.2+ + # "can't add a new key into hash during iteration" + # + def each(&block) + list = [] + self.keys.sort.each do |sidx| + list << [sidx, self[sidx]] + end + list.each(&block) + end + protected # @@ -138,4 +150,4 @@ protected end -end \ No newline at end of file +end