Permalink
Browse files

Ensure we don't return unsuitable interface indicies via RDM, closes #…

  • Loading branch information...
peternewman committed Oct 25, 2018
1 parent 8ba68ff commit 634f1655f5b2fbfb3b07a6f3bcb07958d1815fb9
Showing with 32 additions and 4 deletions.
  1. +27 −4 common/rdm/ResponderHelper.cpp
  2. +3 −0 include/ola/rdm/RDMEnums.h
  3. +2 −0 include/ola/rdm/ResponderHelper.h
@@ -651,19 +651,28 @@ RDMResponse *ResponderHelper::GetListInterfaces(
std::sort(interfaces.begin(), interfaces.end(),
ola::network::InterfaceIndexOrdering());
uint16_t interface_count = std::count_if(
interfaces.begin(), interfaces.end(), IsInterfaceIndexValidInterface);
PACK(
struct list_interfaces_s {
uint32_t index;
uint16_t type;
});
STATIC_ASSERT(sizeof(list_interfaces_s) == 6);
list_interfaces_s list_interfaces[interfaces.size()];
list_interfaces_s list_interfaces[interface_count];
// Reorder so valid interfaces are first
std::stable_partition(interfaces.begin(), interfaces.end(),
IsInterfaceIndexValidInterface);
for (uint16_t i = 0; i < interfaces.size(); i++) {
list_interfaces[i].index = HostToNetwork(interfaces[i].index);
// Then just iterate through the valid ones
vector<Interface>::iterator iter = interfaces.begin();
for (uint16_t i = 0; i < interface_count; i++) {
list_interfaces[i].index = HostToNetwork(iter[i].index);
list_interfaces[i].type = HostToNetwork(
static_cast<uint16_t>(interfaces[i].type));
static_cast<uint16_t>(iter[i].type));
}
return GetResponseFromData(
@@ -1201,10 +1210,24 @@ RDMResponse *ResponderHelper::SetUInt32Value(
bool ResponderHelper::FindInterface(
const NetworkManagerInterface *network_manager,
Interface *interface, uint32_t index) {
if (!IsInterfaceIndexValid(index)) {
// Invalid index
return false;
}
InterfacePicker::Options options;
options.specific_only = true;
return network_manager->GetInterfacePicker()->ChooseInterface(
interface, index, options);
}
bool ResponderHelper::IsInterfaceIndexValid(uint32_t index) {
return (index >= MIN_RDM_INTERFACE_INDEX &&
index <= MAX_RDM_INTERFACE_INDEX);
}
bool ResponderHelper::IsInterfaceIndexValidInterface(Interface interface) {
return IsInterfaceIndexValid(interface.index);
}
} // namespace rdm
} // namespace ola
@@ -692,6 +692,9 @@ typedef enum {
static const uint16_t IPV4_UNCONFIGURED = 0x00000000;
static const uint16_t NO_DEFAULT_ROUTE = 0x00000000;
static const uint32_t MIN_RDM_INTERFACE_INDEX = 0x00000001;
static const uint32_t MAX_RDM_INTERFACE_INDEX = 0xFFFFFF00;
typedef enum {
DHCP_STATUS_INACTIVE = 0x00,
DHCP_STATUS_ACTIVE = 0x01,
@@ -271,6 +271,8 @@ class ResponderHelper {
const NetworkManagerInterface *network_manager,
ola::network::Interface *interface,
uint32_t index);
static bool IsInterfaceIndexValid(uint32_t index);
static bool IsInterfaceIndexValidInterface(ola::network::Interface interface);
};
} // namespace rdm
} // namespace ola

0 comments on commit 634f165

Please sign in to comment.