From 0037d2c767f37087084bd32a1d4ffc3da3ca01ec Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 6 Mar 2014 07:35:46 -0800 Subject: [PATCH] providers/hyperv: validate IP address returned [GH-3069] --- .../providers/hyperv/action/wait_for_ip_address.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/providers/hyperv/action/wait_for_ip_address.rb b/plugins/providers/hyperv/action/wait_for_ip_address.rb index 635d832f2..ad7e80e98 100644 --- a/plugins/providers/hyperv/action/wait_for_ip_address.rb +++ b/plugins/providers/hyperv/action/wait_for_ip_address.rb @@ -1,3 +1,4 @@ +require "ipaddr" require "timeout" module VagrantPlugins @@ -6,6 +7,7 @@ module VagrantPlugins class WaitForIPAddress def initialize(app, env) @app = app + @logger = Log4r::Logger.new("vagrant::hyperv::wait_for_ip_addr") end def call(env) @@ -24,7 +26,16 @@ module VagrantPlugins network_info = env[:machine].provider.driver.execute( "get_network_config.ps1", VmId: env[:machine].id) guest_ip = network_info["ip"] - break if guest_ip && guest_ip != "" + + if guest_ip + begin + IPAddr.new(guest_ip) + break + rescue IPAddr::InvalidAddressError + # Ignore, continue looking. + @logger.warn("Invalid IP address returned: #{guest_ip}") + end + end sleep 1 end