summaryrefslogtreecommitdiffhomepage
path: root/windows
diff options
context:
space:
mode:
authorOdd Stranne <odd@mullvad.net>2020-02-18 21:07:08 +0100
committerOdd Stranne <odd@mullvad.net>2020-02-19 21:36:04 +0100
commit3085bd30191a32e0b8331dd7c7ac933dd44262fd (patch)
tree832c95416187911f8090f7d775a6035334ad8eb8 /windows
parentea42564b8a1ede8b05856baa9ba28ee35628b18b (diff)
downloadmullvadvpn-3085bd30191a32e0b8331dd7c7ac933dd44262fd.tar.xz
mullvadvpn-3085bd30191a32e0b8331dd7c7ac933dd44262fd.zip
WINFW: Correct argument types and add parameter validation on public functions
Diffstat (limited to 'windows')
-rw-r--r--windows/winfw/src/winfw/winfw.cpp114
-rw-r--r--windows/winfw/src/winfw/winfw.h12
2 files changed, 83 insertions, 43 deletions
diff --git a/windows/winfw/src/winfw/winfw.cpp b/windows/winfw/src/winfw/winfw.cpp
index 5388c20449..0af40994e6 100644
--- a/windows/winfw/src/winfw/winfw.cpp
+++ b/windows/winfw/src/winfw/winfw.cpp
@@ -53,23 +53,23 @@ 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.
- uint32_t timeout_ms = 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(timeout_ms);
}
catch (std::exception &err)
@@ -95,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");
+ }
- // Convert seconds to milliseconds.
- uint32_t timeout_ms = timeout * 1000;
+ if (nullptr == settings)
+ {
+ THROW_ERROR("Invalid argument: settings");
+ }
- g_logSink = logSink;
- g_logSinkContext = logSinkContext;
+ // Convert seconds to milliseconds.
+ uint32_t timeout_ms = timeout * 1000;
- try
- {
- g_fwContext = new FwContext(timeout_ms, settings);
+ g_logSink = logSink;
+ g_logSinkContext = logSinkContext;
+
+ g_fwContext = new FwContext(timeout_ms, *settings);
}
catch (std::exception &err)
{
@@ -156,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
)
{
@@ -168,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)
{
@@ -189,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
@@ -203,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)
@@ -211,8 +246,8 @@ WinFw_ApplyPolicyConnected(
}
return g_fwContext->applyPolicyConnected(
- settings,
- relay,
+ *settings,
+ *relay,
tunnelInterfaceAlias,
tunnelDnsServers
);
@@ -236,7 +271,7 @@ WINFW_LINKAGE
bool
WINFW_API
WinFw_ApplyPolicyBlocked(
- const WinFwSettings &settings
+ const WinFwSettings *settings
)
{
if (nullptr == g_fwContext)
@@ -246,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
);
//