From: "d12fk (Code Review)"
Date: Fri, 31 Oct 2025 17:37:26 +0000
In-Reply-To:
References:
Reply-To: heiko@...515..., arne-openvpn@...1227...,
openvpn-devel@lists.sourceforge.net, frank@...2641...,
gert@...1296...
Message-ID: <2d85ab073293938dadfb4bc53c1f0a8795819ac6-EmailReplacePatchSet-HTML@...2715...>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="Y+hPijbEB24="; 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: plaisthos , flichtenheld
Cc: openvpn-devel
--Y+hPijbEB24=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is currently required from: d12fk, flichtenheld, plaisthos.
Hello cron2, flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1307?usp=3Demail
to look at the new patch set (#2).
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
---
M src/openvpnserv/validate.c
1 file changed, 9 insertions(+), 22 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/07/1307/2
diff --git a/src/openvpnserv/validate.c b/src/openvpnserv/validate.c
index 2187fb5..80ccb67 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,39 +58,26 @@
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];
- /* 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, sizeof(config_path), workdir, =
fname);
}
else
{
- config_file =3D fname;
+ res =3D PathCchCanonicalize(config_path, sizeof(config_path), fnam=
e);
}
- /* 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: 2
Gerrit-Owner: d12fk
Gerrit-Reviewer: cron2
Gerrit-Reviewer: flichtenheld
Gerrit-Reviewer: plaisthos
Gerrit-CC: openvpn-devel
Gerrit-Attention: plaisthos
Gerrit-Attention: flichtenheld
Gerrit-Attention: d12fk
--Y+hPijbEB24=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is cur=
rently required from: d12fk, flichtenheld, plaisthos.
d12fk uploaded patch set #2 to this change.
View Change=
a>
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
Si=
gned-off-by: Heiko Hund <heiko@...2662...>
---
M src/openvpnser=
v/validate.c
1 file changed, 9 insertions(+), 22 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/chang=
es/07/1307/2
diff --git a/src/openvpnserv/validate.c b/src/openvpns=
erv/validate.c
index 2187fb5..80ccb67 100644
--- a/src/openvpnserv/validate.c
+++ b/src/openvpnserv/va=
lidate.c
@@ -24,8 +24,8 @@
#include <lmaccess.h>
#include <shlwapi.h><=
/span>
-#include <lm.h><=
/span>
#include <pathcch.h>
+#include <lm.h>
<=
span> #ifndef HAVE_PATHCCH_ENSURE_TRAILING_SLASH
#define P=
ATHCCH_ENSURE_TRAILING_SLASH 0x20
@@ -58,39 +58,26 @@
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 any of the strings
+ * Check that config path is inside config_dir=
+ * The logic here i=
s simple: if the path isn't prefixed with config_dir it's rejected<=
/span>
*/
static BOOL
CheckCon=
figPath(const WCHAR *workdir, const WCHAR *fname, const settings_t *s)
{
- WCH=
AR tmp[MAX_PATH];
- =
const WCHAR *config_file =3D NULL;
- WCHAR config_dir[MAX_PATH];
+ HRESULT res;
+ WCHAR config_path[MAX_PATH];
- /* convert fname to =
full path */
+ /* =
convert fname to full canonical path */
if (PathIsRela=
tiveW(fname))
{
- swprintf(tmp, _countof(tmp), L"%ls\\%ls", =
workdir, fname);
- =
config_file =3D tmp;
+ res =3D PathCchCombine(config_path, sizeof(config_path), workdi=
r, fname);
}
else
{
- config=
_file =3D fname;
+ =
res =3D PathCchCanonicalize(config_path, sizeof(config_path), fname);<=
/span>
}
- /* canonicalize config_dir and add trailing slash be=
fore 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_p=
ath, s->config_dir, wcslen(s->config_dir)) =3D=3D 0;
=
}
=
To view, visit change 1307. To unsubscribe, or for help writing mail filters, v=
isit settings.
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I0e94068f467f2899daf133b032a=
785d2d7fc05e4
Gerrit-Change-Number: 1307
Gerrit-PatchSet: 2
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-CC: openvpn-devel <openvpn-devel@...1484...=
ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...=
..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...=
41...>
Gerrit-Attention: d12fk <heiko@...515...>=
;
=
--Y+hPijbEB24=--