Skip to content

Commit

Permalink
Check that the address sent via thrift is Ipv4.
Browse files Browse the repository at this point in the history
In case an IPv6 address is sent in the ip_address field of AddPort thrift,
it is accepted and later when to_v4() is invoked, bad_cast exception is
thrown.

Change-Id: I0a8e8991c6891ab61fd00c9eaa0e21f3e3ffaff5
partial-bug: 1476613
  • Loading branch information
haripk committed Jul 23, 2015
1 parent 9bc2f1d commit 86e67b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/vnsw/agent/openstack/instance_service_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ InstanceServiceAsyncHandler::AddPort(const PortList& port_list) {
boost::system::error_code ec;
IpAddress ip = IpAddress::from_string(port.ip_address, ec);
bool v4_valid = (ec.value() == 0);
if (v4_valid == false) {
if (v4_valid == false || ip.is_v4() == false) {
CFG_TRACE(IntfInfo,
"IPv4 address is not correct, " + port.ip_address);
v4_valid = false;
ip = IpAddress();
}

bool v6_valid = false;
Expand Down
11 changes: 11 additions & 0 deletions src/vnsw/agent/openstack/test/test_instance_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,17 @@ TEST_F(InstanceServiceTest, AddPortWrongIP) {
TASK_UTIL_EXPECT_EQ(0, cfg_table_->Size());
}

// Wrong IP address : send IPv6 address
TEST_F(InstanceServiceTest, AddPortWrongIPIsv6) {
Port port;
InitPortInfo(port, 2, 2, 2, PortTypes::NovaVMPort);
port.ip_address = "30:32::03";
AddPort(port);
client->WaitForIdle();

TASK_UTIL_EXPECT_EQ(0, cfg_table_->Size());
}

// Null uuids, ports do get created
TEST_F(InstanceServiceTest, NullUUIDTest) {
Port port;
Expand Down

0 comments on commit 86e67b7

Please sign in to comment.