diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fdad08a6..77bdabcbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.6.6 (unreleased) - + - Fix potential infinite loop with root path if bad CWD is given to environment. ## 0.6.5 (October 8, 2010) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index a11bcea12..be88cce3e 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -243,7 +243,7 @@ module Vagrant root_finder = lambda do |path| return path if File.exist?(File.join(path.to_s, ROOTFILE_NAME)) - return nil if path.root? + return nil if path.root? || !File.exist?(path) root_finder.call(path.parent) end diff --git a/test/vagrant/environment_test.rb b/test/vagrant/environment_test.rb index 9ede33d4e..f2634debd 100644 --- a/test/vagrant/environment_test.rb +++ b/test/vagrant/environment_test.rb @@ -242,6 +242,7 @@ class EnvironmentTest < Test::Unit::TestCase search_seq = sequence("search_seq") paths.each do |path| File.expects(:exist?).with(path.join(@klass::ROOTFILE_NAME).to_s).returns(false).in_sequence(search_seq) + File.expects(:exist?).with(path).returns(true).in_sequence(search_seq) if !path.root? end assert !@klass.new(:cwd => paths.first).root_path @@ -254,6 +255,10 @@ class EnvironmentTest < Test::Unit::TestCase assert_equal path, @klass.new(:cwd => path).root_path end + should "not infinite loop on relative paths" do + assert @klass.new(:cwd => "../test").root_path.nil? + end + should "only load the root path once" do env = @klass.new File.expects(:exist?).with(env.cwd.join(@klass::ROOTFILE_NAME).to_s).returns(true).once