diff options
| -rw-r--r-- | windows/windns/src/windns/windns.cpp | 68 |
1 files changed, 62 insertions, 6 deletions
diff --git a/windows/windns/src/windns/windns.cpp b/windows/windns/src/windns/windns.cpp index 362915301b..48ad863dfa 100644 --- a/windows/windns/src/windns/windns.cpp +++ b/windows/windns/src/windns/windns.cpp @@ -167,15 +167,71 @@ WinDns_Recover( uint32_t dataLength ) { - common::serialization::Deserializer d(reinterpret_cast<const uint8_t *>(configData), dataLength); + std::vector<InterfaceConfig> configs; - uint32_t numConfigs; - d >> numConfigs; + try + { + common::serialization::Deserializer d(reinterpret_cast<const uint8_t *>(configData), dataLength); + + auto numConfigs = d.decode<uint32_t>(); + + if (numConfigs > 50) + { + return false; + } + + configs.reserve(numConfigs); + + for (; numConfigs != 0; --numConfigs) + { + configs.emplace_back(InterfaceConfig(d)); + } + } + catch (std::exception &err) + { + if (nullptr != g_ErrorSink) + { + auto msg = std::string("Failed to deserialize recovery data: ").append(err.what()); + + g_ErrorSink(msg.c_str(), g_ErrorContext); + } + + return false; + } + catch (...) + { + return false; + } - for (; numConfigs != 0; --numConfigs) + if (configs.empty()) { - nchelpers::RevertDnsServers(InterfaceConfig(d)); + return true; } - return true; + bool success = true; + + for (const auto &config : configs) + { + try + { + nchelpers::RevertDnsServers(config); + } + catch (std::exception &err) + { + if (nullptr != g_ErrorSink) + { + auto msg = std::string("Failed to restore interface settings: ").append(err.what()); + + g_ErrorSink(msg.c_str(), g_ErrorContext); + } + + success = false; + } + catch (...) + { + success = false; + } + } + + return success; } |
