summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOdd Stranne <odd@mullvad.net>2020-02-19 22:02:24 +0100
committerOdd Stranne <odd@mullvad.net>2020-02-19 22:02:24 +0100
commit8cd98e9c84be8fa6540e3c4e1ee1c5a5a6db7533 (patch)
tree900f5027272c343ea63a6087f1f6591407b8ed23
parent47b5079254521f2ddd1d4d0b220a6d36a55801e7 (diff)
parenta4cf19266db57268d0064b40593bf9efa623ca23 (diff)
downloadmullvadvpn-8cd98e9c84be8fa6540e3c4e1ee1c5a5a6db7533.tar.xz
mullvadvpn-8cd98e9c84be8fa6540e3c4e1ee1c5a5a6db7533.zip
Merge branch 'win-fix-module-interfaces'
-rw-r--r--windows/windns/src/windns/windns.cpp10
-rw-r--r--windows/winfw/src/winfw/winfw.cpp118
-rw-r--r--windows/winfw/src/winfw/winfw.h12
-rw-r--r--windows/winnet/src/winnet/winnet.cpp45
4 files changed, 137 insertions, 48 deletions
diff --git a/windows/windns/src/windns/windns.cpp b/windows/windns/src/windns/windns.cpp
index 26e891521d..72db7a00b8 100644
--- a/windows/windns/src/windns/windns.cpp
+++ b/windows/windns/src/windns/windns.cpp
@@ -255,6 +255,12 @@ WinDns_Set(
return false;
}
+ if (nullptr == interfaceAlias)
+ {
+ g_LogSink->error("Invalid argument: interfaceAlias");
+ return false;
+ }
+
//
// Check the settings on the adapter.
// If it already has the exact same settings we need, we're done.
@@ -277,12 +283,12 @@ WinDns_Set(
return true;
}
}
- catch (const std::exception & ex)
+ catch (const std::exception &err)
{
std::stringstream ss;
ss << "Failed to evaluate DNS settings on adapter with alias \""
- << common::string::ToAnsi(interfaceAlias) << "\": " << ex.what();
+ << common::string::ToAnsi(interfaceAlias) << "\": " << err.what();
g_LogSink->info(ss.str().c_str());
}
diff --git a/windows/winfw/src/winfw/winfw.cpp b/windows/winfw/src/winfw/winfw.cpp
index dc0dbe3387..0af40994e6 100644
--- a/windows/winfw/src/winfw/winfw.cpp
+++ b/windows/winfw/src/winfw/winfw.cpp
@@ -9,8 +9,6 @@
namespace
{
-uint32_t g_timeout = 0;
-
MullvadLogSink g_logSink = nullptr;
void *g_logSinkContext = nullptr;
@@ -55,24 +53,24 @@ WinFw_Initialize(
void *logSinkContext
)
{
- if (nullptr != g_fwContext)
+ try
{
- //
- // This is an error.
- // The existing instance may have a different timeout etc.
- //
- return false;
- }
+ if (nullptr != g_fwContext)
+ {
+ //
+ // This is an error.
+ // The existing instance may have a different timeout etc.
+ //
+ THROW_ERROR("Cannot initialize WINFW twice");
+ }
- // Convert seconds to milliseconds.
- g_timeout = timeout * 1000;
+ // Convert seconds to milliseconds.
+ uint32_t timeout_ms = timeout * 1000;
- g_logSink = logSink;
- g_logSinkContext = logSinkContext;
+ g_logSink = logSink;
+ g_logSinkContext = logSinkContext;
- try
- {
- g_fwContext = new FwContext(g_timeout);
+ g_fwContext = new FwContext(timeout_ms);
}
catch (std::exception &err)
{
@@ -97,29 +95,34 @@ bool
WINFW_API
WinFw_InitializeBlocked(
uint32_t timeout,
- const WinFwSettings &settings,
+ const WinFwSettings *settings,
MullvadLogSink logSink,
void *logSinkContext
)
{
- if (nullptr != g_fwContext)
+ try
{
- //
- // This is an error.
- // The existing instance may have a different timeout etc.
- //
- return false;
- }
+ if (nullptr != g_fwContext)
+ {
+ //
+ // This is an error.
+ // The existing instance may have a different timeout etc.
+ //
+ THROW_ERROR("Cannot initialize WINFW twice");
+ }
+
+ if (nullptr == settings)
+ {
+ THROW_ERROR("Invalid argument: settings");
+ }
- // Convert seconds to milliseconds.
- g_timeout = timeout * 1000;
+ // Convert seconds to milliseconds.
+ uint32_t timeout_ms = timeout * 1000;
- g_logSink = logSink;
- g_logSinkContext = logSinkContext;
+ g_logSink = logSink;
+ g_logSinkContext = logSinkContext;
- try
- {
- g_fwContext = new FwContext(g_timeout, settings);
+ g_fwContext = new FwContext(timeout_ms, *settings);
}
catch (std::exception &err)
{
@@ -158,8 +161,8 @@ WINFW_LINKAGE
bool
WINFW_API
WinFw_ApplyPolicyConnecting(
- const WinFwSettings &settings,
- const WinFwRelay &relay,
+ const WinFwSettings *settings,
+ const WinFwRelay *relay,
const PingableHosts *pingableHosts
)
{
@@ -170,7 +173,17 @@ WinFw_ApplyPolicyConnecting(
try
{
- return g_fwContext->applyPolicyConnecting(settings, relay, ConvertPingableHosts(pingableHosts));
+ if (nullptr == settings)
+ {
+ THROW_ERROR("Invalid argument: settings");
+ }
+
+ if (nullptr == relay)
+ {
+ THROW_ERROR("Invalid argument: relay");
+ }
+
+ return g_fwContext->applyPolicyConnecting(*settings, *relay, ConvertPingableHosts(pingableHosts));
}
catch (std::exception &err)
{
@@ -191,8 +204,8 @@ WINFW_LINKAGE
bool
WINFW_API
WinFw_ApplyPolicyConnected(
- const WinFwSettings &settings,
- const WinFwRelay &relay,
+ const WinFwSettings *settings,
+ const WinFwRelay *relay,
const wchar_t *tunnelInterfaceAlias,
const wchar_t *v4DnsHost,
const wchar_t *v6DnsHost
@@ -205,6 +218,26 @@ WinFw_ApplyPolicyConnected(
try
{
+ if (nullptr == settings)
+ {
+ THROW_ERROR("Invalid argument: settings");
+ }
+
+ if (nullptr == relay)
+ {
+ THROW_ERROR("Invalid argument: relay");
+ }
+
+ if (nullptr == tunnelInterfaceAlias)
+ {
+ THROW_ERROR("Invalid argument: tunnelInterfaceAlias");
+ }
+
+ if (nullptr == v4DnsHost)
+ {
+ THROW_ERROR("Invalid argument: v4DnsHost");
+ }
+
std::vector<wfp::IpAddress> tunnelDnsServers = { wfp::IpAddress(v4DnsHost) };
if (nullptr != v6DnsHost)
@@ -213,8 +246,8 @@ WinFw_ApplyPolicyConnected(
}
return g_fwContext->applyPolicyConnected(
- settings,
- relay,
+ *settings,
+ *relay,
tunnelInterfaceAlias,
tunnelDnsServers
);
@@ -238,7 +271,7 @@ WINFW_LINKAGE
bool
WINFW_API
WinFw_ApplyPolicyBlocked(
- const WinFwSettings &settings
+ const WinFwSettings *settings
)
{
if (nullptr == g_fwContext)
@@ -248,7 +281,12 @@ WinFw_ApplyPolicyBlocked(
try
{
- return g_fwContext->applyPolicyBlocked(settings);
+ if (nullptr == settings)
+ {
+ THROW_ERROR("Invalid argument: settings");
+ }
+
+ return g_fwContext->applyPolicyBlocked(*settings);
}
catch (std::exception &err)
{
diff --git a/windows/winfw/src/winfw/winfw.h b/windows/winfw/src/winfw/winfw.h
index c95890dd4a..e989d69f57 100644
--- a/windows/winfw/src/winfw/winfw.h
+++ b/windows/winfw/src/winfw/winfw.h
@@ -87,7 +87,7 @@ bool
WINFW_API
WinFw_InitializeBlocked(
uint32_t timeout,
- const WinFwSettings &settings,
+ const WinFwSettings *settings,
MullvadLogSink logSink,
void *logSinkContext
);
@@ -133,8 +133,8 @@ WINFW_LINKAGE
bool
WINFW_API
WinFw_ApplyPolicyConnecting(
- const WinFwSettings &settings,
- const WinFwRelay &relay,
+ const WinFwSettings *settings,
+ const WinFwRelay *relay,
const PingableHosts *pingableHosts
);
@@ -159,8 +159,8 @@ WINFW_LINKAGE
bool
WINFW_API
WinFw_ApplyPolicyConnected(
- const WinFwSettings &settings,
- const WinFwRelay &relay,
+ const WinFwSettings *settings,
+ const WinFwRelay *relay,
const wchar_t *tunnelInterfaceAlias,
const wchar_t *v4DnsHost,
const wchar_t *v6DnsHost
@@ -177,7 +177,7 @@ WINFW_LINKAGE
bool
WINFW_API
WinFw_ApplyPolicyBlocked(
- const WinFwSettings &settings
+ const WinFwSettings *settings
);
//
diff --git a/windows/winnet/src/winnet/winnet.cpp b/windows/winnet/src/winnet/winnet.cpp
index b71484bf7c..2a96d150ca 100644
--- a/windows/winnet/src/winnet/winnet.cpp
+++ b/windows/winnet/src/winnet/winnet.cpp
@@ -43,6 +43,11 @@ WinNet_EnsureBestMetric(
{
try
{
+ if (nullptr == deviceAlias)
+ {
+ THROW_ERROR("Invalid argument: deviceAlias");
+ }
+
NetworkInterfaces interfaces;
return interfaces.SetBestMetricForInterfacesByAlias(deviceAlias) ?
WINNET_EBM_STATUS_METRIC_SET : WINNET_EBM_STATUS_METRIC_NO_CHANGE;
@@ -111,6 +116,11 @@ WinNet_GetTapInterfaceAlias(
{
try
{
+ if (nullptr == alias)
+ {
+ THROW_ERROR("Invalid argument: alias");
+ }
+
const auto currentAlias = InterfaceUtils::GetTapInterfaceAlias();
auto stringBuffer = new wchar_t[currentAlias.size() + 1];
@@ -166,6 +176,11 @@ WinNet_ActivateConnectivityMonitor(
THROW_ERROR("Cannot activate connectivity monitor twice");
}
+ if (nullptr == callback)
+ {
+ THROW_ERROR("Invalid argument: callback");
+ }
+
auto forwarder = [callback, callbackContext](bool connected)
{
callback(connected, callbackContext);
@@ -257,6 +272,11 @@ WinNet_AddRoutes(
try
{
+ if (nullptr == routes)
+ {
+ THROW_ERROR("Invalid argument: routes");
+ }
+
g_RouteManager->addRoutes(winnet::ConvertRoutes(routes, numRoutes));
return true;
}
@@ -300,6 +320,11 @@ WinNet_DeleteRoutes(
try
{
+ if (nullptr == routes)
+ {
+ THROW_ERROR("Invalid argument: routes");
+ }
+
g_RouteManager->deleteRoutes(winnet::ConvertRoutes(routes, numRoutes));
return true;
}
@@ -344,6 +369,16 @@ WinNet_RegisterDefaultRouteChangedCallback(
try
{
+ if (nullptr == callback)
+ {
+ THROW_ERROR("Invalid argument: callback");
+ }
+
+ if (nullptr == registrationHandle)
+ {
+ THROW_ERROR("Invalid argument: registrationHandle");
+ }
+
auto forwarder = [callback, context](RouteManager::DefaultRouteChangedEventType eventType,
ADDRESS_FAMILY family, const std::optional<InterfaceAndGateway> &route)
{
@@ -469,6 +504,16 @@ WinNet_AddDeviceIpAddresses(
{
try
{
+ if (nullptr == deviceAlias)
+ {
+ THROW_ERROR("Invalid argument: deviceAlias")
+ }
+
+ if (nullptr == addresses)
+ {
+ THROW_ERROR("Invalid argument: addresses")
+ }
+
NET_LUID luid;
if (0 != ConvertInterfaceAliasToLuid(deviceAlias, &luid))