From: "d12fk (Code Review)" Date: Fri, 31 Oct 2025 19:34:46 +0000 References: Reply-To: heiko@...515..., 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="P/rf5l2m7Iw="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: iservice: make sure directories have trailing \ List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --P/rf5l2m7Iw= 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/+/1336?usp=3Demail to review the following change. Change subject: iservice: make sure directories have trailing \ ...................................................................... iservice: make sure directories have trailing \ 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 --- M src/openvpnserv/common.c 1 file changed, 33 insertions(+), 6 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/1336/1 diff --git a/src/openvpnserv/common.c b/src/openvpnserv/common.c index d25d9c0..969b8ac 100644 --- a/src/openvpnserv/common.c +++ b/src/openvpnserv/common.c @@ -54,6 +54,33 @@ } +/** + * 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(WSTR dir, size_t size) +{ + size_t len =3D wcslen(dir); + + if (dir[len - 1] !=3D '\\') + { + if (len + 1 > size) + { + return FALSE; + } + dir[len] =3D '\\'; + dir[len + 1] =3D '\0'; + } + + return TRUE; +} + + DWORD GetOpenvpnSettings(settings_t *s) { @@ -90,16 +117,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 +137,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: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f Gerrit-Change-Number: 1336 Gerrit-PatchSet: 1 Gerrit-Owner: d12fk Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld --P/rf5l2m7Iw= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

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

d12fk would like plaisthos and flichtenheld to review t= his change.

V= iew Change

iservice: make sure directories have traili=
ng \

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 miss= ing \
at the end would allow a string compare to succeed, if the last el= ement of
the path to compare starts with the same substring. The trailin= g slash
ensures that the last element of a path must match completely.
Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f
Signed-off-by= : Heiko Hund <heiko@...2662...>
---
M src/openvpnserv/common.c<= br>1 file changed, 33 insertions(+), 6 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/1336/1<=
/pre>
+/**
+ * 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 ro= om in the buffer.
+ *=
+ * @param dir = pointer to the wide dir path string buffer
+ * @param size maximum number of wide chars th= e dir path buffer
+ *= @return BOOL to indicate success or failure
+ */
+static BOOL
= +ensure_trailing_backslash(WSTR dir, size_t size)
+{
+ size_t len =3D wcslen(dir);
+
+ if (dir[len - 1] !=3D '\\')
+ {
+ if (len + 1 > size)
+ {
+ return FALSE;
+ }
+ dir[len] =3D '\\';
+ dir[len + 1] =3D '\0';
+ }
+
+ return TRUE;
+}
+
<= span style=3D"color: hsl(120, 100%, 40%);">+
DWORD<= br> GetOpenvpnSettings(settings_t *s)
{
@@ -90,16 +117,16 @@
goto out;
}

- swprintf(default_value, _countof(default_value), L"%ls\\config= ", install_path);
- if (error = !=3D ERROR_SUCCESS)
+= if (error !=3D ERROR_SUCCESS || !ensure_trailing_backslash(s->config= _dir, _countof(s->config_dir)))
{
= goto out;
}

- swprintf(default_value, _countof(d= efault_value), L"%ls\\bin", install_path);
+ swprintf(default_value, _countof(defa= ult_value), L"%ls\\bin\\", install_path);
er= ror =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_bac= kslash(s->bin_dir, _countof(s->bin_dir)))
{
goto out;
}
@@ -1= 10,9 +137,9 @@
goto out;
}


- sw= printf(default_value, _countof(default_value), L"%ls\\log", insta= ll_path);
+ swprin= tf(default_value, _countof(default_value), L"%ls\\log\\", install= _path);
error =3D GetRegString(key, L"log_dir&quo= t;, 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 change 1336. To un= subscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If28e66fcc3493821f78fd14d432= b22b996918e8f
Gerrit-Change-Number: 1336
Gerrit-PatchSet: 1
Gerrit-Owner: d12fk <heiko@...515...>
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...>
= --P/rf5l2m7Iw=--