Skip to content

Commit 82867fb

Browse files
committed
Prevent duplicate migrations_paths
[#50099107] If Msf::DBManager#initialize_metasploit_data_models is run multiple times, such as during specs, ActiveRecord::Migrator.migrations_paths was getting populated with multiple copies of the metasploit_data_models db/migrate path, which would lead to 'DB.migrate threw an exception: Multiple migrations have the version number 0' errors in framework.log.
1 parent 51a89c3 commit 82867fb

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/msf/core/db_manager.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,16 @@ def initialize_metasploit_data_models
163163
'db',
164164
'migrate'
165165
)
166-
ActiveRecord::Migrator.migrations_paths << metasploit_data_model_migrations_pathname.to_s
166+
metasploit_data_model_migrations_path = metasploit_data_model_migrations_pathname.to_s
167+
168+
# Since ActiveRecord::Migrator.migrations_paths can persist between
169+
# instances of Msf::DBManager, such as in specs,
170+
# metasploit_data_models_migrations_path may already be part of
171+
# migrations_paths, in which case it should not be added or multiple
172+
# migrations with the same version number errors will occur.
173+
unless ActiveRecord::Migrator.migrations_paths.include? metasploit_data_model_migrations_path
174+
ActiveRecord::Migrator.migrations_paths << metasploit_data_model_migrations_path
175+
end
167176
end
168177

169178
#

0 commit comments

Comments
 (0)