From: "cron2 (Code Review)" Date: Wed, 12 Nov 2025 11:27:02 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., heiko@...515..., openvpn-devel@lists.sourceforge.net, frank@...2641..., lstipakov@...277... Message-ID: <525003bd2cfd73d4880b5d752994afe349e12b97-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="CletepLjMKU="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: iservice: make sure directories have trailing backslash List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: d12fk Cc: stipa , plaisthos , flichtenheld , openvpn-devel --CletepLjMKU= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/13= 36?usp=3Demail ) Change subject: iservice: make sure directories have trailing backslash ...................................................................... iservice: make sure directories have trailing backslash At least in the case of the config dir this matters, since the value is used to validate input data for the interactive service. A missing \ at the end would allow a string compare to succeed, if the last element of the path to compare starts with the same substring. The trailing slash ensures that the last element of a path must match completely. Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f Signed-off-by: Heiko Hund Acked-by: Lev Stipakov Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1336 Message-Id: <20251109154438.15464-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg34= 285.html Signed-off-by: Gert Doering --- M src/openvpnserv/common.c 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/openvpnserv/common.c b/src/openvpnserv/common.c index d25d9c0..b1c89c9 100644 --- a/src/openvpnserv/common.c +++ b/src/openvpnserv/common.c @@ -24,6 +24,8 @@ #include "validate.h" #include "eventmsg.h" +#include + LPCWSTR service_instance =3D L""; static wchar_t win_sys_path[MAX_PATH]; @@ -54,6 +56,22 @@ } +/** + * Make sure that a dir path ends with a backslash. + * If it doesn't, a \ is added to the end of the path, if there's room in = the buffer. + * + * @param dir pointer to the wide dir path string buffer + * @param size maximum number of wide chars the dir path buffer + * @return BOOL to indicate success or failure + */ +static BOOL +ensure_trailing_backslash(PWSTR dir, size_t size) +{ + HRESULT res =3D PathCchAddBackslash(dir, size); + return (res =3D=3D S_OK || res =3D=3D S_FALSE) ? TRUE : FALSE; +} + + DWORD GetOpenvpnSettings(settings_t *s) { @@ -90,16 +108,16 @@ goto out; } - swprintf(default_value, _countof(default_value), L"%ls\\config", insta= ll_path); + swprintf(default_value, _countof(default_value), L"%ls\\config\\", ins= tall_path); error =3D GetRegString(key, L"config_dir", s->config_dir, sizeof(s->co= nfig_dir), default_value); - if (error !=3D ERROR_SUCCESS) + if (error !=3D ERROR_SUCCESS || !ensure_trailing_backslash(s->config_d= ir, _countof(s->config_dir))) { goto out; } - swprintf(default_value, _countof(default_value), L"%ls\\bin", install_= path); + swprintf(default_value, _countof(default_value), L"%ls\\bin\\", instal= l_path); error =3D GetRegString(key, L"bin_dir", s->bin_dir, sizeof(s->bin_dir)= , default_value); - if (error !=3D ERROR_SUCCESS) + if (error !=3D ERROR_SUCCESS || !ensure_trailing_backslash(s->bin_dir,= _countof(s->bin_dir))) { goto out; } @@ -110,9 +128,9 @@ goto out; } - swprintf(default_value, _countof(default_value), L"%ls\\log", install_= path); + swprintf(default_value, _countof(default_value), L"%ls\\log\\", instal= l_path); error =3D GetRegString(key, L"log_dir", s->log_dir, sizeof(s->log_dir)= , default_value); - if (error !=3D ERROR_SUCCESS) + if (error !=3D ERROR_SUCCESS || !ensure_trailing_backslash(s->log_dir,= _countof(s->log_dir))) { goto out; } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1336?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: merged Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f Gerrit-Change-Number: 1336 Gerrit-PatchSet: 9 Gerrit-Owner: d12fk Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-Reviewer: stipa Gerrit-CC: openvpn-devel --CletepLjMKU= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change.

View Change

iservice: make sure directories have trailing ba=
ckslash

At least in the case of the config dir this matters, since t= he value is
used to validate input data for the interactive service. A m= issing \
at the end would allow a string compare to succeed, if the last= element of
the path to compare starts with the same substring. The trai= ling slash
ensures that the last element of a path must match completely= .

Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f
Signed-off= -by: Heiko Hund <heiko@...2662...>
Acked-by: Lev Stipakov <lsti= pakov@...277...>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1= 336
Message-Id: <20251109154438.15464-1-gert@...1296...>
URL: h= ttps://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg34285.ht= ml
Signed-off-by: Gert Doering <gert@...1296...>
---
M src/o= penvpnserv/common.c
1 file changed, 24 insertions(+), 6 deletions(-)
=
diff --git a/src/openvpnserv/common.c b/src/openvpnserv/common.c<=
br>index d25d9c0..b1c89c9 100644
--- a/src/openvpnser= v/common.c
+++ b/src/openvpnserv/common.c
@= @ -24,6 +24,8 @@
#include "validate.h" #include "eventmsg.h"

+#include <pathcch.h>
= +
LPCWSTR serv= ice_instance =3D L"";
static wchar_t win_sys_pat= h[MAX_PATH];

@@ -54,6 +56,22 @@ }


+/**
+ * Make sure that a dir path ends with a backslash.
+ * If it doesn't, a \ is adde= d to the end of the path, if there's room in the buffer.
+ *
+ * @param dir pointer to the wide dir path st= ring buffer
+ * @para= m size maximum number of wide chars the dir path buffer
+ * @return BOOL to indicate succes= s or failure
+ */

+static BOOL
<= span style=3D"color: hsl(120, 100%, 40%);">+ensure_trailing_backslash(PWSTR= dir, size_t size)
+{=
+ HRESULT res =3D= PathCchAddBackslash(dir, size);
+ return (res =3D=3D S_OK || res =3D=3D S_FALSE) ? TRUE : FA= LSE;
+}
+
+
DWORD
GetOpenvpnS= ettings(settings_t *s)
{
@@ -90,16 +108,16= @@
goto out;
}

- swprintf(defa= ult_value, _countof(default_value), L"%ls\\config", install_path)= ;
+ swprintf(defau= lt_value, _countof(default_value), L"%ls\\config\\", install_path= );
error =3D GetRegString(key, L"config_dir"= , s->config_dir, sizeof(s->config_dir), default_value);
- if (error !=3D ERROR_SUCCESS)
+ if (error !=3D ER= ROR_SUCCESS || !ensure_trailing_backslash(s->config_dir, _countof(s->= config_dir)))
{
goto out;

}

- swprintf(default_value, _countof(default_value), L"= ;%ls\\bin", install_path);
+ swprintf(default_value, _countof(default_value), L"%ls= \\bin\\", install_path);
error =3D GetRegString(k= ey, L"bin_dir", s->bin_dir, sizeof(s->bin_dir), default_val= ue);
- if (error != =3D ERROR_SUCCESS)
+ = if (error !=3D ERROR_SUCCESS || !ensure_trailing_backslash(s->bin_dir= , _countof(s->bin_dir)))
{
= goto out;
}
@@ -110,9 +128,9 @@
goto out;
}

- swprintf(default_value= , _countof(default_value), L"%ls\\log", install_path);
= + swprintf(default_value, _c= ountof(default_value), L"%ls\\log\\", install_path);
error =3D GetRegString(key, L"log_dir", s->log_dir, s= izeof(s->log_dir), default_value);

- if (error !=3D ERROR_SUCCESS)
+ if (error !=3D ERROR_SUCCESS || !ensure_t= railing_backslash(s->log_dir, _countof(s->log_dir)))
= {
goto out;
}
=

To view, visit change 1336. To unsubscribe, or for he= lp writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If28e66fcc3493821f78fd14d432= b22b996918e8f
Gerrit-Change-Number: 1336
Gerrit-PatchSet: 9
Gerrit-Owner: d12fk <heiko@...515...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-Reviewer: stipa <lstipakov@...277...= >
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --CletepLjMKU=--