Permalink
Browse files

Merge pull request #547 from jhsrennie/master

Fix potential infinite loop in CPeripherals::LoadMappings
  • Loading branch information...
2 parents c051742 + cf65342 commit cc49b8581491436578d89fa5e4a85b71728e5d63 John Rennie committed Nov 27, 2011
Showing with 10 additions and 4 deletions.
  1. +10 −4 xbmc/peripherals/Peripherals.cpp
@@ -385,24 +385,31 @@ bool CPeripherals::LoadMappings(void)
return false;
}
- TiXmlElement *currentNode = pRootElement->FirstChildElement("peripheral");
- while (currentNode)
+ for (TiXmlElement *currentNode = pRootElement->FirstChildElement("peripheral"); currentNode; currentNode = currentNode->NextSiblingElement("peripheral"))
{
CStdStringArray vpArray, idArray;
PeripheralID id;
PeripheralDeviceMapping mapping;
+ mapping.m_strDeviceName = currentNode->Attribute("name") ? CStdString(currentNode->Attribute("name")) : StringUtils::EmptyString;
+
// If there is no vendor_product attribute ignore this entry
if (!currentNode->Attribute("vendor_product"))
+ {
+ CLog::Log(LOGERROR, "%s - ignoring node \"%s\" with missing vendor_product attribute", __FUNCTION__, mapping.m_strDeviceName.c_str());
continue;
+ }
// The vendor_product attribute is a list of comma separated vendor:product pairs
StringUtils::SplitString(currentNode->Attribute("vendor_product"), ",", vpArray);
for (unsigned int i = 0; i < vpArray.size(); i++)
{
StringUtils::SplitString(vpArray[i], ":", idArray);
if (idArray.size() != 2)
+ {
+ CLog::Log(LOGERROR, "%s - ignoring node \"%s\" with invalid vendor_product attribute", __FUNCTION__, mapping.m_strDeviceName.c_str());
continue;
+ }
id.m_iVendorId = PeripheralTypeTranslator::HexStringToInt(idArray[0]);
id.m_iProductId = PeripheralTypeTranslator::HexStringToInt(idArray[1]);
@@ -413,12 +420,11 @@ bool CPeripherals::LoadMappings(void)
mapping.m_busType = PeripheralTypeTranslator::GetBusTypeFromString(currentNode->Attribute("bus"));
mapping.m_class = PeripheralTypeTranslator::GetTypeFromString(currentNode->Attribute("class"));
- mapping.m_strDeviceName = currentNode->Attribute("name") ? CStdString(currentNode->Attribute("name")) : StringUtils::EmptyString;
mapping.m_mappedTo = PeripheralTypeTranslator::GetTypeFromString(currentNode->Attribute("mapTo"));
GetSettingsFromMappingsFile(currentNode, mapping.m_settings);
m_mappings.push_back(mapping);
- currentNode = currentNode->NextSiblingElement("peripheral");
+ CLog::Log(LOGDEBUG, "%s - loaded node \"%s\"", __FUNCTION__, mapping.m_strDeviceName.c_str());
}
return true;

0 comments on commit cc49b85

Please sign in to comment.