summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-24 01:29:29 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-24 01:29:29 -0500
commit725e3f9f0c401aa34bb0d3d01bb8119797d038f7 (patch)
treeb0c50230f073208d9c31e9e181c50deee74a4d72
parent240ff8c1d9e5b03d27804490767c15b7877305a2 (diff)
downloadhorizon-725e3f9f0c401aa34bb0d3d01bb8119797d038f7.tar.gz
horizon-725e3f9f0c401aa34bb0d3d01bb8119797d038f7.tar.bz2
horizon-725e3f9f0c401aa34bb0d3d01bb8119797d038f7.tar.xz
horizon-725e3f9f0c401aa34bb0d3d01bb8119797d038f7.zip
hscript: Ensure netaddress iface name is < IFNAMSIZ
-rw-r--r--hscript/network.cc7
-rw-r--r--tests/fixtures/0130-netaddress-invalid-iface.installfile6
-rw-r--r--tests/spec/validator_spec.rb5
3 files changed, 18 insertions, 0 deletions
diff --git a/hscript/network.cc b/hscript/network.cc
index b751e7e..e8f27b9 100644
--- a/hscript/network.cc
+++ b/hscript/network.cc
@@ -62,6 +62,13 @@ Key *NetAddress::parseFromData(const std::string &data, int lineno, int *errors,
type_pos = data.find_first_of(' ');
iface = data.substr(0, type_pos);
+ if(iface.length() > IFNAMSIZ) {
+ if(errors) *errors += 1;
+ output_error("installfile:" + std::to_string(lineno),
+ "netaddress: interface name '" + iface + "' is invalid",
+ "interface names must be 16 characters or less");
+ return nullptr;
+ }
/* theory: addr_pos could be npos, but that means 'read to end' anyway */
addr_pos = data.find_first_of(' ', type_pos + 1);
if(addr_pos == std::string::npos) next_end = std::string::npos;
diff --git a/tests/fixtures/0130-netaddress-invalid-iface.installfile b/tests/fixtures/0130-netaddress-invalid-iface.installfile
new file mode 100644
index 0000000..e641c26
--- /dev/null
+++ b/tests/fixtures/0130-netaddress-invalid-iface.installfile
@@ -0,0 +1,6 @@
+network false
+hostname test.machine
+pkginstall adelie-base
+rootpw $6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/
+mount /dev/sda1 /
+netaddress enP20p36s15f10d16 dhcp
diff --git a/tests/spec/validator_spec.rb b/tests/spec/validator_spec.rb
index 624eaa2..b07e383 100644
--- a/tests/spec/validator_spec.rb
+++ b/tests/spec/validator_spec.rb
@@ -293,6 +293,11 @@ RSpec.describe 'HorizonScript validation', :type => :aruba do
run_validate
expect(last_command_started).to have_output(/error: .*netaddress.*require/)
end
+ it "fails with invalid interface name" do
+ use_fixture '0130-netaddress-invalid-iface.installfile'
+ run_validate
+ expect(last_command_started).to have_output(/error: .*netaddress.*interface/)
+ end
# Runner.Validate.netaddress.Validity.Type.
it "fails on invalid address type" do
use_fixture '0037-netaddress-invalid-type.installfile'