From 59846378b3c7ffb427718c6a2375873a73909b69 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 10 Jun 2018 16:02:49 -0400 Subject: [PATCH] BTReal: Handle case where a link key may be invalid within LoadLinkKeys() This can only occur if a user purposely corrupts their config file, but still, we may as well protect users from themselves. --- Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp b/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp index 174d0bb0da..243493d5f1 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp @@ -514,8 +514,17 @@ void BluetoothReal::LoadLinkKeys() if (index == std::string::npos) continue; - bdaddr_t address = Common::StringToMacAddress(pair.substr(0, index)).value(); - std::reverse(address.begin(), address.end()); + const std::string address_string = pair.substr(0, index); + std::optional address = Common::StringToMacAddress(address_string); + if (!address) + { + ERROR_LOG(IOS_WIIMOTE, "Malformed MAC address (%s). Skipping loading of current link key.", + address_string.c_str()); + continue; + } + + auto& mac = address.value(); + std::reverse(mac.begin(), mac.end()); const std::string& key_string = pair.substr(index + 1); linkkey_t key{}; @@ -527,7 +536,7 @@ void BluetoothReal::LoadLinkKeys() key[pos++] = value; } - m_link_keys[address] = key; + m_link_keys[mac] = key; } }