diff options
| author | Odd Stranne <odd@mullvad.net> | 2018-06-13 16:16:39 +0200 |
|---|---|---|
| committer | Odd Stranne <odd@mullvad.net> | 2018-06-18 09:08:12 +0200 |
| commit | 1c245ffc5ab79410bbb24b752cb56b480f15e325 (patch) | |
| tree | ae0b64d46cedd6717bd714eab13da3b98847a1da /windows | |
| parent | 98a716dba4ec2d96c112fbfdc68a6154eebb6dce (diff) | |
| download | mullvadvpn-1c245ffc5ab79410bbb24b752cb56b480f15e325.tar.xz mullvadvpn-1c245ffc5ab79410bbb24b752cb56b480f15e325.zip | |
Improve failure handling inside WinDns_Recover
Diffstat (limited to 'windows')
| -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; } |
