From bd5fd7ab1853b1d3d1e28ff70798fc12499b4b57 Mon Sep 17 00:00:00 2001 From: Jeff Ramnani Date: Mon, 20 Oct 2014 11:51:27 -0500 Subject: [PATCH] Fix #4658. Bad NFS exports file on OS X & BSD hosts. For FreeBSD guests, Virtualbox can sometimes report the private network interface IP address as "0.0.0.0". This will cause an invalid NFS exports file to be generated for FreeBSD and OS X hosts. Fixed by not allowing Virtualbox to report a guest IP address of "0.0.0.0". --- .../providers/virtualbox/driver/version_4_0.rb | 17 ++++++++++++++++- .../providers/virtualbox/driver/version_4_1.rb | 17 ++++++++++++++++- .../providers/virtualbox/driver/version_4_2.rb | 17 ++++++++++++++++- .../providers/virtualbox/driver/version_4_3.rb | 17 ++++++++++++++++- .../virtualbox_driver_version_4_x_examples.rb | 11 +++++++++++ 5 files changed, 75 insertions(+), 4 deletions(-) diff --git a/plugins/providers/virtualbox/driver/version_4_0.rb b/plugins/providers/virtualbox/driver/version_4_0.rb index 670adfd0a..1f032f3ed 100644 --- a/plugins/providers/virtualbox/driver/version_4_0.rb +++ b/plugins/providers/virtualbox/driver/version_4_0.rb @@ -269,7 +269,12 @@ module VagrantPlugins end def read_guest_ip(adapter_number) - read_guest_property("/VirtualBox/GuestInfo/Net/#{adapter_number}/V4/IP") + ip = read_guest_property("/VirtualBox/GuestInfo/Net/#{adapter_number}/V4/IP") + if !valid_ip_address?(ip) + raise Vagrant::Errors::VirtualBoxGuestPropertyNotFound, guest_property: "/VirtualBox/GuestInfo/Net/#{adapter_number}/V4/IP" + end + + return ip end def read_guest_property(property) @@ -500,6 +505,16 @@ module VagrantPlugins end end + def valid_ip_address?(ip) + # Filter out invalid IP addresses + # GH-4658 VirtualBox can report an IP address of 0.0.0.0 for FreeBSD guests. + if ip == "0.0.0.0" + return false + else + return true + end + end + def verify! # This command sometimes fails if kernel drivers aren't properly loaded # so we just run the command and verify that it succeeded. diff --git a/plugins/providers/virtualbox/driver/version_4_1.rb b/plugins/providers/virtualbox/driver/version_4_1.rb index 60bbdadad..28fe76f4d 100644 --- a/plugins/providers/virtualbox/driver/version_4_1.rb +++ b/plugins/providers/virtualbox/driver/version_4_1.rb @@ -274,7 +274,12 @@ module VagrantPlugins end def read_guest_ip(adapter_number) - read_guest_property("/VirtualBox/GuestInfo/Net/#{adapter_number}/V4/IP") + ip = read_guest_property("/VirtualBox/GuestInfo/Net/#{adapter_number}/V4/IP") + if !valid_ip_address?(ip) + raise Vagrant::Errors::VirtualBoxGuestPropertyNotFound, guest_property: "/VirtualBox/GuestInfo/Net/#{adapter_number}/V4/IP" + end + + return ip end def read_guest_property(property) @@ -510,6 +515,16 @@ module VagrantPlugins end end + def valid_ip_address?(ip) + # Filter out invalid IP addresses + # GH-4658 VirtualBox can report an IP address of 0.0.0.0 for FreeBSD guests. + if ip == "0.0.0.0" + return false + else + return true + end + end + def verify! # This command sometimes fails if kernel drivers aren't properly loaded # so we just run the command and verify that it succeeded. diff --git a/plugins/providers/virtualbox/driver/version_4_2.rb b/plugins/providers/virtualbox/driver/version_4_2.rb index cbc397f3e..e867aa3d3 100644 --- a/plugins/providers/virtualbox/driver/version_4_2.rb +++ b/plugins/providers/virtualbox/driver/version_4_2.rb @@ -305,7 +305,12 @@ module VagrantPlugins end def read_guest_ip(adapter_number) - read_guest_property("/VirtualBox/GuestInfo/Net/#{adapter_number}/V4/IP") + ip = read_guest_property("/VirtualBox/GuestInfo/Net/#{adapter_number}/V4/IP") + if !valid_ip_address?(ip) + raise Vagrant::Errors::VirtualBoxGuestPropertyNotFound, guest_property: "/VirtualBox/GuestInfo/Net/#{adapter_number}/V4/IP" + end + + return ip end def read_guest_property(property) @@ -541,6 +546,16 @@ module VagrantPlugins end end + def valid_ip_address?(ip) + # Filter out invalid IP addresses + # GH-4658 VirtualBox can report an IP address of 0.0.0.0 for FreeBSD guests. + if ip == "0.0.0.0" + return false + else + return true + end + end + def verify! # This command sometimes fails if kernel drivers aren't properly loaded # so we just run the command and verify that it succeeded. diff --git a/plugins/providers/virtualbox/driver/version_4_3.rb b/plugins/providers/virtualbox/driver/version_4_3.rb index cc700c0fa..b9955e3ff 100644 --- a/plugins/providers/virtualbox/driver/version_4_3.rb +++ b/plugins/providers/virtualbox/driver/version_4_3.rb @@ -314,7 +314,12 @@ module VagrantPlugins end def read_guest_ip(adapter_number) - read_guest_property("/VirtualBox/GuestInfo/Net/#{adapter_number}/V4/IP") + ip = read_guest_property("/VirtualBox/GuestInfo/Net/#{adapter_number}/V4/IP") + if !valid_ip_address?(ip) + raise Vagrant::Errors::VirtualBoxGuestPropertyNotFound, guest_property: "/VirtualBox/GuestInfo/Net/#{adapter_number}/V4/IP" + end + + return ip end def read_guest_property(property) @@ -550,6 +555,16 @@ module VagrantPlugins end end + def valid_ip_address?(ip) + # Filter out invalid IP addresses + # GH-4658 VirtualBox can report an IP address of 0.0.0.0 for FreeBSD guests. + if ip == "0.0.0.0" + return false + else + return true + end + end + def verify! # This command sometimes fails if kernel drivers aren't properly loaded # so we just run the command and verify that it succeeded. diff --git a/test/unit/plugins/providers/virtualbox/support/shared/virtualbox_driver_version_4_x_examples.rb b/test/unit/plugins/providers/virtualbox/support/shared/virtualbox_driver_version_4_x_examples.rb index cb84e2325..ad99827c6 100644 --- a/test/unit/plugins/providers/virtualbox/support/shared/virtualbox_driver_version_4_x_examples.rb +++ b/test/unit/plugins/providers/virtualbox/support/shared/virtualbox_driver_version_4_x_examples.rb @@ -38,5 +38,16 @@ shared_examples "a version 4.x virtualbox driver" do |options| expect(value).to eq("127.1.2.3") end + + it "does not accept 0.0.0.0 as a valid IP address" do + key = "/VirtualBox/GuestInfo/Net/1/V4/IP" + + expect(subprocess).to receive(:execute). + with("VBoxManage", "guestproperty", "get", uuid, key, an_instance_of(Hash)). + and_return(subprocess_result(stdout: "Value: 0.0.0.0")) + + expect { subject.read_guest_ip(1) }. + to raise_error Vagrant::Errors::VirtualBoxGuestPropertyNotFound + end end end