From: "cron2 (Code Review)"
Date: Wed, 12 Nov 2025 10:22:43 +0000
In-Reply-To:
References:
Reply-To: gert@...1296..., arne-openvpn@...1227..., heiko@...515...,
selva.nair@...277..., openvpn-devel@lists.sourceforge.net,
frank@...2641..., lstipakov@...277...
Message-ID: <1f98798b850be2d505609f585c400aed053f0526-EmailReplacePatchSet-HTML@...2715...>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="zdXKyMH/XCs="; charset=UTF-8
Subject: [Openvpn-devel] [S] Change in openvpn[master]: iservice: validate
config path better
List-Id:
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
To: d12fk , plaisthos , flichtenheld , selvanair , stipa
Cc: openvpn-devel
--zdXKyMH/XCs=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
cron2 has uploaded a new patch set (#8) to the change originally created by=
d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/1307?usp=3Demail )
The following approvals got outdated and were removed:
Code-Review+1 by cron2, Code-Review+2 by stipa
Change subject: iservice: validate config path better
......................................................................
iservice: validate config path better
Instead of just rejecting any path that contains ".." use some WIN32 API
functions to combine, canonicalize and then check if the resulting
path is located under the config directory. Makes the code prettier
and more correct.
Change-Id: I0e94068f467f2899daf133b032a785d2d7fc05e4
Signed-off-by: Heiko Hund
Acked-by: Lev Stipakov
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1307
Message-Id: <20251112092244.22764-1-gert@...1296...>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg34=
336.html
Signed-off-by: Gert Doering
---
M src/openvpnserv/validate.c
1 file changed, 9 insertions(+), 22 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/07/1307/8
diff --git a/src/openvpnserv/validate.c b/src/openvpnserv/validate.c
index ddaa381..2dcfe1a 100644
--- a/src/openvpnserv/validate.c
+++ b/src/openvpnserv/validate.c
@@ -24,8 +24,8 @@
#include
#include
-#include
#include
+#include
#ifndef HAVE_PATHCCH_ENSURE_TRAILING_SLASH
#define PATHCCH_ENSURE_TRAILING_SLASH 0x20
@@ -58,44 +58,31 @@
static PTOKEN_GROUPS GetTokenGroups(const HANDLE token);
/*
- * Check workdir\fname is inside config_dir
- * The logic here is simple: we may reject some valid paths if ..\ is in a=
ny of the strings
+ * Check that config path is inside config_dir
+ * The logic here is simple: if the path isn't prefixed with config_dir it=
's rejected
*/
static BOOL
CheckConfigPath(const WCHAR *workdir, const WCHAR *fname, const settings_t=
*s)
{
- WCHAR tmp[MAX_PATH];
- const WCHAR *config_file =3D NULL;
- WCHAR config_dir[MAX_PATH];
+ HRESULT res;
+ WCHAR config_path[MAX_PATH];
=20
/* fname =3D stdin is special: do not treat it as a relative path */
if (wcscmp(fname, L"stdin") =3D=3D 0)
{
return FALSE;
}
- /* convert fname to full path */
+ /* convert fname to full canonical path */
if (PathIsRelativeW(fname))
{
- swprintf(tmp, _countof(tmp), L"%ls\\%ls", workdir, fname);
- config_file =3D tmp;
+ res =3D PathCchCombine(config_path, _countof(config_path), workdir=
, fname);
}
else
{
- config_file =3D fname;
+ res =3D PathCchCanonicalize(config_path, _countof(config_path), fn=
ame);
}
- /* 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 (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;
- }
-
- return FALSE;
+ return res =3D=3D S_OK && wcsncmp(config_path, s->config_dir, wcslen(s=
->config_dir)) =3D=3D 0;
}
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1307?usp=3Demail
To unsubscribe, or for help writing mail filters, visit http://gerrit.openv=
pn.net/settings?usp=3Demail
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I0e94068f467f2899daf133b032a785d2d7fc05e4
Gerrit-Change-Number: 1307
Gerrit-PatchSet: 8
Gerrit-Owner: d12fk
Gerrit-Reviewer: cron2
Gerrit-Reviewer: flichtenheld
Gerrit-Reviewer: plaisthos
Gerrit-Reviewer: selvanair
Gerrit-Reviewer: stipa
Gerrit-CC: openvpn-devel
--zdXKyMH/XCs=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
cron2 upl=
oaded patch set #8 to the change originally created by d12fk.
<=
p>View C=
hange
The following approvals got outdated and were removed:
Code-Review+1 by cron2, Code-Review+2 by stipa
iservice: v=
alidate config path better
Instead of just rejecting any path that c=
ontains ".." use some WIN32 API
functions to combine, canonica=
lize and then check if the resulting
path is located under the config di=
rectory. Makes the code prettier
and more correct.
Change-Id: I0e=
94068f467f2899daf133b032a785d2d7fc05e4
Signed-off-by: Heiko Hund <hei=
ko@...2662...>
Acked-by: Lev Stipakov <lstipakov@...277...>
=
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1307
Message-Id: <=
20251112092244.22764-1-gert@...1296...>
URL: https://www.mail-archive=
.com/openvpn-devel@lists.sourceforge.net/msg34336.html
Signed-off-by: Ge=
rt Doering <gert@...1296...>
---
M src/openvpnserv/validate.c1 file changed, 9 insertions(+), 22 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/07/1307/8<=
/pre>diff --git a/src/openvpnserv/validate.c b/src/openvpnserv/validate.=
c
index ddaa381..2dcfe1a 100644
--- a/src/o=
penvpnserv/validate.c
+++ b/src/openvpnserv/validate.c
@@ -24,8 +24,8 @@
#include &=
lt;lmaccess.h>
#include <shlwapi.h>
-#include <lm.h>
#include <pathcch.h>
+#include <lm.h>
#ifndef=
HAVE_PATHCCH_ENSURE_TRAILING_SLASH
#define PATHCCH_ENSURE=
_TRAILING_SLASH 0x20
@@ -58,44 +58,31 @@
s=
tatic PTOKEN_GROUPS GetTokenGroups(const HANDLE token);
=
span>
/*
- * =
Check workdir\fname is inside config_dir
- * The logic here is simple: we may reject some valid pa=
ths if ..\ is in any of the strings
+ * Check that config path is inside config_dir
+ * The logic here is simple: if =
the path isn't prefixed with config_dir it's rejected
*/
static BOOL
CheckConfigPath(const=
WCHAR *workdir, const WCHAR *fname, const settings_t *s)
=
{
- WCHAR tmp[MAX_PA=
TH];
- const WCHAR *=
config_file =3D NULL;
-=
WCHAR config_dir[MAX_PATH];
+ HRESULT res;
+ WCHAR config_path[MAX_PATH];
/* fname =3D stdin is special: do not treat it as a relative path */<=
/span>
if (wcscmp(fname, L"stdin") =3D=3D 0)=
{
return FALSE;
=
}
- /* convert fna=
me to full path */
+ =
/* convert fname to full canonical path */
if (Path=
IsRelativeW(fname))
{
- swprintf(tmp, _countof(tmp), L"%ls\\%ls&q=
uot;, workdir, fname);
=
- config_file =3D tmp;
+ res =3D PathCchCombine(config_path, _countof(config_path)=
, workdir, fname);
}
else<=
br> {
- =
config_file =3D fname;
+ res =3D PathCchCanonicalize(config_path, _countof(config_path)=
, fname);
}
- /* canonicalize config_dir and add trailin=
g slash before comparison */
- HRESULT res =3D PathCchCanonicalizeEx(config_dir, _countof(confi=
g_dir), s->config_dir,
- PATHCCH_ENSURE_TRAILING_SLASH);=
-
- if (res =3D=3D S_OK
- && wcsncmp(config_dir, c=
onfig_file, wcslen(config_dir)) =3D=3D 0
- && wcsstr(config_file + wcslen(config_di=
r), L"..") =3D=3D NULL)
- {
- =
return TRUE;
- }=
-
- return FALSE;
+ return res =3D=3D S_OK && wcsncm=
p(config_path, s->config_dir, wcslen(s->config_dir)) =3D=3D 0;=
}
To view, visit change 1307. To unsubscribe, or for help writing mail =
filters, visit s=
ettings.
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I0e94068f467f2899daf133b032a=
785d2d7fc05e4
Gerrit-Change-Number: 1307
Gerrit-PatchSet: 8
Gerrit-Owner: d12fk <heiko@...515...> =
div>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...=
1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...=
.1227...>
Gerrit-Reviewer: selvanair <selva.nair@...1665...=
77...>
Gerrit-Reviewer: stipa <lstipakov@...277...=
>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...=
ts.sourceforge.net>
=
--zdXKyMH/XCs=--