From: "selvanair (Code Review)" Date: Mon, 27 Oct 2025 20:27:04 +0000 References: Reply-To: selva.nair@...277..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="TTx2tUyiomU="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Canonicalize config_dir before comparing with the config file location List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --TTx2tUyiomU= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1318?usp=3Demail to review the following change. Change subject: Canonicalize config_dir before comparing with the config fi= le location ...................................................................... Canonicalize config_dir before comparing with the config file location Found by ZeroPath Change-Id: I8e884c00cb94f97a612056e8dca74d821a6d6386 Signed-off-by: Selva Nair --- M src/openvpnserv/CMakeLists.txt M src/openvpnserv/validate.c 2 files changed, 17 insertions(+), 4 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/18/1318/1 diff --git a/src/openvpnserv/CMakeLists.txt b/src/openvpnserv/CMakeLists.txt index 340b904..a92ee08 100644 --- a/src/openvpnserv/CMakeLists.txt +++ b/src/openvpnserv/CMakeLists.txt @@ -6,6 +6,11 @@ add_executable(openvpnserv) +include(CheckSymbolExists) + +# Some old versions of mingw does not have PATHCCH_OPTIONS enums -- add a = check +check_symbol_exists(PATHCCH_ENSURE_TRAILING_SLASH pathcch.h HAVE_PATHCCH_E= NSURE_TRAILING_SLASH) + set(MC_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/mc) target_include_directories(openvpnserv PRIVATE @@ -31,7 +36,7 @@ ) target_link_libraries(openvpnserv advapi32.lib userenv.lib iphlpapi.lib fwpuclnt.lib rpcrt4.lib - shlwapi.lib netapi32.lib ws2_32.lib ntdll.lib ole32.lib) + shlwapi.lib netapi32.lib ws2_32.lib ntdll.lib ole32.lib pathcch.lib) if (MINGW) target_compile_options(openvpnserv PRIVATE -municode) target_link_options(openvpnserv PRIVATE -municode) diff --git a/src/openvpnserv/validate.c b/src/openvpnserv/validate.c index 59d5b86..2187fb5 100644 --- a/src/openvpnserv/validate.c +++ b/src/openvpnserv/validate.c @@ -25,6 +25,11 @@ #include #include #include +#include + +#ifndef HAVE_PATHCCH_ENSURE_TRAILING_SLASH +#define PATHCCH_ENSURE_TRAILING_SLASH 0x20 +#endif static const WCHAR *white_list[] =3D { L"auth-retry", @@ -61,7 +66,7 @@ { WCHAR tmp[MAX_PATH]; const WCHAR *config_file =3D NULL; - const WCHAR *config_dir =3D NULL; + WCHAR config_dir[MAX_PATH]; /* convert fname to full path */ if (PathIsRelativeW(fname)) @@ -74,9 +79,12 @@ config_file =3D fname; } - config_dir =3D s->config_dir; + /* canonicalize config_dir and add trailing slash before comparison */ + HRESULT res =3D PathCchCanonicalizeEx(config_dir, _countof(config_dir)= , s->config_dir, + PATHCCH_ENSURE_TRAILING_SLASH); - if (wcsncmp(config_dir, config_file, wcslen(config_dir)) =3D=3D 0 + if (res =3D=3D S_OK + && wcsncmp(config_dir, config_file, wcslen(config_dir)) =3D=3D 0 && wcsstr(config_file + wcslen(config_dir), L"..") =3D=3D NULL) { return TRUE; -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1318?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I8e884c00cb94f97a612056e8dca74d821a6d6386 Gerrit-Change-Number: 1318 Gerrit-PatchSet: 1 Gerrit-Owner: selvanair Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld --TTx2tUyiomU= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: flichtenheld, plaisthos.

selvanair would like plaisthos and flichtenheld to review this change.

V= iew Change

Canonicalize config_dir before comparing wi=
th the config file location

Found by ZeroPath

Change-Id: I8e8= 84c00cb94f97a612056e8dca74d821a6d6386
Signed-off-by: Selva Nair <selv= a.nair@...277...>
---
M src/openvpnserv/CMakeLists.txt
M src/op= envpnserv/validate.c
2 files changed, 17 insertions(+), 4 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn r=
efs/changes/18/1318/1
diff --git a/src/openvpnserv/CMakeLists.txt b=
/src/openvpnserv/CMakeLists.txt
index 340b904..a92ee08 1006= 44
--- a/src/openvpnserv/CMakeLists.txt
+++= b/src/openvpnserv/CMakeLists.txt
@@ -6,6 +6,11 @@
add_executable(openvpnserv)

+include(CheckSymbolExi= sts)
+
+# Some old versions of mingw does = not have PATHCCH_OPTIONS enums -- add a check

+check_symbol_exists(PATHCCH_ENSURE_TRAILING_SLASH= pathcch.h HAVE_PATHCCH_ENSURE_TRAILING_SLASH)
+
set(MC_GEN_DIR ${CMAKE_CURRENT= _BINARY_DIR}/mc)

target_include_director= ies(openvpnserv PRIVATE
@@ -31,7 +36,7 @@
= )
target_link_libraries(openvpnserv
= advapi32.lib userenv.lib iphlpapi.lib fwpuclnt.lib rpcrt4.lib
= - shlwapi.lib netapi32.lib ws2= _32.lib ntdll.lib ole32.lib)
+ shlwapi.lib netapi32.lib ws2_32.lib ntdll.lib ole32.lib pathcc= h.lib)
if (MINGW)
target_compile_opti= ons(openvpnserv PRIVATE -municode)
target_link_options= (openvpnserv PRIVATE -municode)
diff --git a/src/openvpnser= v/validate.c b/src/openvpnserv/validate.c
index 59d5b86..21= 87fb5 100644
--- a/src/openvpnserv/validate.c
+++ b/src/openvpnserv/validate.c
@@ -25,6 +25,11 @@
#include <lmaccess.h>
#include <shlw= api.h>
#include <lm.h>
+#include <pathcch.h>
+
+#ifndef HAVE_PATHCCH_ENSURE_TRAILING_SLASH
+#define PATHCCH_ENSURE_TRAILING_SLA= SH 0x20

+#endif

static const WCHAR *white_list[] =3D {=
L"auth-retry",
@@ -61,7 +66,7 @@
{
WCHAR tmp[MAX_PATH];
const WCHAR *config_file =3D NULL;

- const WCHAR *config_dir =3D NULL;
+ WCHAR config_dir[MAX_PATH];=

/* convert fname to full path */ if (PathIsRelativeW(fname))
@@ -74,9 +79,12 @@<= /span>
config_file =3D fname;
}

- conf= ig_dir =3D s->config_dir;
+ /* canonicalize config_dir and add trailing slash before compa= rison */
+ HRESULT= res =3D PathCchCanonicalizeEx(config_dir, _countof(config_dir), s->conf= ig_dir,
+ = PATHCCH_ENSURE_TRAILING_SLASH);

- if (wcsncmp(con= fig_dir, config_file, wcslen(config_dir)) =3D=3D 0
+ if (res =3D=3D S_OK
+ && wcsncmp(config_dir, c= onfig_file, wcslen(config_dir)) =3D=3D 0
&&= ; wcsstr(config_file + wcslen(config_dir), L"..") =3D=3D NULL)
{
return TRUE;
=

To view, visit change 1318. To unsubscribe, or for help wri= ting mail filters, visit settings.

=
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8e884c00cb94f97a612056e8dca= 74d821a6d6386
Gerrit-Change-Number: 1318
Gerrit-PatchSet: 1
Gerrit-Owner: selvanair <selva.nair@...1354...= ..>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
= --TTx2tUyiomU=--