From: "cron2 (Code Review)" Date: Sat, 24 Jan 2026 17:21:34 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., heiko@...515..., 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="M3diMIkEWEU="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: openvpnserv: Factor out the string conversion from GetItfDnsDomains List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld , plaisthos , d12fk Cc: openvpn-devel --M3diMIkEWEU= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#7) to the change originally created by= flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1458?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by d12fk Change subject: openvpnserv: Factor out the string conversion from GetItfDn= sDomains ...................................................................... openvpnserv: Factor out the string conversion from GetItfDnsDomains Mostly so that we can actually test it. Since that code does some in-place conversions a test would be good. Change-Id: Ib517457015b754d59aeb70827c4795aa6154728c Signed-off-by: Frank Lichtenheld Acked-by: Heiko Hund Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1458 Message-Id: <20260119214927.27766-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg35= 343.html Signed-off-by: Gert Doering --- M src/openvpnserv/interactive.c 1 file changed, 101 insertions(+), 72 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/58/1458/7 diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index b6ab2b8..ad19e2c 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -2143,6 +2143,106 @@ } /** + * Convert interface specific domain suffix(es) from comma-separated + * string to MULTI_SZ string. + * + * The \p domains paramter will be set to a MULTI_SZ domains string. + * In case of an error \p size is set to 0 and the contents of \p domains + * are invalid. + * Note that domains are deleted from the string if they match a search do= main. + * + * @param[in] search_domains optional list of search domains + * @param[in,out] domains buffer that contains the input comma-sep= arated + * string and will contain the MULTI_SZ out= put string + * @param[in,out] size pointer to size of the input string in b= ytes. Will be + * set to the size of the string returned, = including + * the terminating zeros or 0. + * @param[in] buf_size size of the \p domains buffer + * + * @return LSTATUS NO_ERROR if the domain suffix(es) were read successfull= y, + * ERROR_FILE_NOT_FOUND if no domain was found for the interface, + * ERROR_MORE_DATA if the list did not fit into the buffer + */ +static LSTATUS +ConvertItfDnsDomains(PCWSTR search_domains, PWSTR domains, PDWORD size, co= nst DWORD buf_size) +{ + const DWORD glyph_size =3D sizeof(*domains); + const DWORD buf_len =3D buf_size / glyph_size; + + /* + * Found domain(s), now convert them: + * - prefix each domain with a dot + * - convert comma separated list to MULTI_SZ + */ + PWCHAR pos =3D domains; + while (TRUE) + { + /* Terminate the domain at the next comma */ + PWCHAR comma =3D wcschr(pos, ','); + if (comma) + { + *comma =3D '\0'; + } + + DWORD domain_len =3D (DWORD)wcslen(pos); + DWORD domain_size =3D domain_len * glyph_size; + DWORD converted_size =3D (DWORD)(pos - domains) * glyph_size; + + /* Ignore itf domains which match a pushed search domain */ + if (ListContainsDomain(search_domains, pos, domain_len)) + { + if (comma) + { + /* Overwrite the ignored domain with remaining one(s) */ + memmove(pos, comma + 1, buf_size - converted_size); + *size -=3D domain_size + glyph_size; + continue; + } + else + { + /* This was the last domain */ + *pos =3D '\0'; + *size -=3D domain_size; + return wcslen(domains) ? NO_ERROR : ERROR_FILE_NOT_FOUND; + } + } + + /* Add space for the leading dot */ + domain_len +=3D 1; + domain_size +=3D glyph_size; + + /* Space for the terminating zeros */ + const DWORD extra_size =3D 2 * glyph_size; + + /* Check for enough space to convert this domain */ + if (converted_size + domain_size + extra_size > buf_size) + { + /* Domain doesn't fit, bad luck if it's the first one */ + *pos =3D '\0'; + *size =3D converted_size =3D=3D 0 ? 0 : converted_size + glyph= _size; + return ERROR_MORE_DATA; + } + + /* Prefix domain at pos with the dot */ + memmove(pos + 1, pos, buf_size - converted_size - glyph_size); + domains[buf_len - 1] =3D '\0'; + *pos =3D '.'; + *size +=3D glyph_size; + + if (!comma) + { + /* Conversion is done */ + *(pos + domain_len) =3D '\0'; + *size +=3D glyph_size; + return NO_ERROR; + } + + /* Comma pos is now +1 after adding leading dot */ + pos =3D comma + 2; + } +} + +/** * Return interface specific domain suffix(es) * * The \p domains paramter will be set to a MULTI_SZ domains string. @@ -2174,7 +2274,6 @@ LSTATUS err =3D ERROR_FILE_NOT_FOUND; const DWORD buf_size =3D *size; const DWORD glyph_size =3D sizeof(*domains); - const DWORD buf_len =3D buf_size / glyph_size; PWSTR values[] =3D { L"SearchList", L"Domain", L"DhcpDomainSearchList"= , L"DhcpDomain", NULL }; for (int i =3D 0; values[i]; i++) @@ -2183,77 +2282,7 @@ err =3D RegGetValueW(itf, NULL, values[i], RRF_RT_REG_SZ, NULL, (P= BYTE)domains, size); if (!err && *size > glyph_size && domains[(*size / glyph_size) - 1= ] =3D=3D '\0' && wcschr(domains, '.')) { - /* - * Found domain(s), now convert them: - * - prefix each domain with a dot - * - convert comma separated list to MULTI_SZ - */ - PWCHAR pos =3D domains; - while (TRUE) - { - /* Terminate the domain at the next comma */ - PWCHAR comma =3D wcschr(pos, ','); - if (comma) - { - *comma =3D '\0'; - } - - DWORD domain_len =3D (DWORD)wcslen(pos); - DWORD domain_size =3D domain_len * glyph_size; - DWORD converted_size =3D (DWORD)(pos - domains) * glyph_si= ze; - - /* Ignore itf domains which match a pushed search domain */ - if (ListContainsDomain(search_domains, pos, domain_len)) - { - if (comma) - { - /* Overwrite the ignored domain with remaining one= (s) */ - memmove(pos, comma + 1, buf_size - converted_size); - *size -=3D domain_size + glyph_size; - continue; - } - else - { - /* This was the last domain */ - *pos =3D '\0'; - *size -=3D domain_size; - return wcslen(domains) ? NO_ERROR : ERROR_FILE_NOT= _FOUND; - } - } - - /* Add space for the leading dot */ - domain_len +=3D 1; - domain_size +=3D glyph_size; - - /* Space for the terminating zeros */ - const DWORD extra_size =3D 2 * glyph_size; - - /* Check for enough space to convert this domain */ - if (converted_size + domain_size + extra_size > buf_size) - { - /* Domain doesn't fit, bad luck if it's the first one = */ - *pos =3D '\0'; - *size =3D converted_size =3D=3D 0 ? 0 : converted_size= + glyph_size; - return ERROR_MORE_DATA; - } - - /* Prefix domain at pos with the dot */ - memmove(pos + 1, pos, buf_size - converted_size - glyph_si= ze); - domains[buf_len - 1] =3D '\0'; - *pos =3D '.'; - *size +=3D glyph_size; - - if (!comma) - { - /* Conversion is done */ - *(pos + domain_len) =3D '\0'; - *size +=3D glyph_size; - return NO_ERROR; - } - - /* Comma pos is now +1 after adding leading dot */ - pos =3D comma + 2; - } + return ConvertItfDnsDomains(search_domains, domains, size, buf= _size); } } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1458?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: Ib517457015b754d59aeb70827c4795aa6154728c Gerrit-Change-Number: 1458 Gerrit-PatchSet: 7 Gerrit-Owner: flichtenheld Gerrit-Reviewer: d12fk Gerrit-Reviewer: plaisthos Gerrit-CC: cron2 Gerrit-CC: openvpn-devel --M3diMIkEWEU= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 upl= oaded patch set #7 to the change originally created by flichtenhel= d.

View Change

The following approvals got outdated and were remove= d: Code-Review+2 by d12fk

openvpnserv: Factor out the string =
conversion from GetItfDnsDomains

Mostly so that we can actually test= it. Since that
code does some in-place conversions a test would be
g= ood.

Change-Id: Ib517457015b754d59aeb70827c4795aa6154728c
Signed-= off-by: Frank Lichtenheld <frank@...2641...>
Acked-by: Heiko Hund = <heiko@...515...>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn= /+/1458
Message-Id: <20260119214927.27766-1-gert@...1296...>
UR= L: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg3534= 3.html
Signed-off-by: Gert Doering <gert@...1296...>
---
M s= rc/openvpnserv/interactive.c
1 file changed, 101 insertions(+), 72 delet= ions(-)

git pull ssh://gerrit.openvpn.net:29418/=
openvpn refs/changes/58/1458/7
diff --git a/src/openvpnserv/interac=
tive.c b/src/openvpnserv/interactive.c
index b6ab2b8..ad19e= 2c 100644
--- a/src/openvpnserv/interactive.c
+++ b/src/openvpnserv/interactive.c
@@ -2143,6 +2143,106= @@
}

/**
+ * Convert interface specific dom= ain suffix(es) from comma-separated
+ * string to MULTI_SZ string.
+ *
+ * The \p domains paramter will be set to a MULTI_SZ domains strin= g.
+ * In case of an = error \p size is set to 0 and the contents of \p domains
+ * are invalid.
+ * Note that domains are deleted from the= string if they match a search domain.
+ *
+ * @param[in] search_domains optional list of search domains<= br>+ * @param[in,out] domains = buffer that contains the input comma-separated
+ * string = and will contain the MULTI_SZ output string
+ * @param[in,out] size pointer to size o= f the input string in bytes. Will be
+ * set to the size of the s= tring returned, including
+ * the terminating zeros or 0.<= br>+ * @param[in] buf_size = size of the \p domains buffer
+ *
+= * @return LSTATUS NO_ERROR if the domain suffix(es) were read successfully= ,
+ * ERROR_F= ILE_NOT_FOUND if no domain was found for the interface,
+ * ERROR_MORE_DATA if the list = did not fit into the buffer
+ */
+static L= STATUS
+ConvertItfDns= Domains(PCWSTR search_domains, PWSTR domains, PDWORD size, const DWORD buf_= size)
+{
+ const DWORD glyph_size =3D s= izeof(*domains);
+ = const DWORD buf_len =3D buf_size / glyph_size;
+
+ /*
+ = * Found domain(s), now convert them:
+ * - prefix each domain with a dot
+ * - convert comma separated l= ist to MULTI_SZ
+ = */
+ PWCHAR pos = =3D domains;
+ whi= le (TRUE)
+ {
+ /* Terminate the= domain at the next comma */
+ PWCHAR comma =3D wcschr(pos, ',');
+ if (comma)

+ {
+ *comma =3D '\0';+ }
+
+ DWORD domain_len =3D (DWORD)wcslen(pos);+ DWORD domain_size =3D= domain_len * glyph_size;
+ DWORD converted_size =3D (DWORD)(pos - domains) * glyph_size;=
+
+ /* Ignore itf domains which ma= tch a pushed search domain */
+ if (ListContainsDomain(search_domains, pos, domain_len))<= /span>
+ {
= + if (comma)<= br>+ {
+ /* Overwrite the = ignored domain with remaining one(s) */

+ memmove(pos, comma + 1, buf_size - conv= erted_size);
+ = *size -=3D domain_size + glyph_size;
+ continue;
+ }
+ else
+ {
+ /* This was the last domain */+ *pos =3D '= ;\0';
+ = *size -=3D domain_size;
+ return wcslen(domains) ? NO_ERROR : ERROR_FILE_NO= T_FOUND;
+ = }
+ }<= br>+
+ /* Add space for the leading dot */

+ domain_len += =3D 1;
+ domai= n_size +=3D glyph_size;
+
+ /* Spac= e for the terminating zeros */
+ const DWORD extra_size =3D 2 * glyph_size;
+
+ /* Check for enough space to convert this do= main */
+ if (= converted_size + domain_size + extra_size > buf_size)
+ {
+ /* Domain doesn't fit, bad luck = if it's the first one */
+ *pos =3D '\0';
+ *size =3D converted_size =3D=3D 0 ? 0 := converted_size + glyph_size;
+ return ERROR_MORE_DATA;
+ }
+
+ = /* Prefix domain at pos with the dot */
+ memmove(pos + 1, pos, buf_size - converted= _size - glyph_size);
= + domains[buf_len - 1] =3D '\0';
+ *pos =3D '.';
+ *size +=3D glyph_size;=
+
+ if (!comma)
+ {
+ /* Conversion is done */
+ *(pos + domain_len) =3D &#= 39;\0';
+ = *size +=3D glyph_size;
+ return NO_ERROR;
+ }
+
+ /* Co= mma pos is now +1 after adding leading dot */
+ pos =3D comma + 2;
+ }
+}
+
+/**
* Return interface specific domain suffix(es)
*
* The \p domains paramter will be set to a MULTI_SZ domains s= tring.
@@ -2174,7 +2274,6 @@
LSTATUS e= rr =3D ERROR_FILE_NOT_FOUND;
const DWORD buf_size =3D = *size;
const DWORD glyph_size =3D sizeof(*domains);
- const DWORD buf_len = =3D buf_size / glyph_size;
PWSTR values[] =3D { L"= ;SearchList", L"Domain", L"DhcpDomainSearchList", = L"DhcpDomain", NULL };

for= (int i =3D 0; values[i]; i++)
@@ -2183,77 +2282,7 @@
err =3D RegGetValueW(itf, NULL, values[i], RRF_RT_REG_S= Z, NULL, (PBYTE)domains, size);
if (!err &&= ; *size > glyph_size && domains[(*size / glyph_size) - 1] =3D=3D= '\0' && wcschr(domains, '.'))
= {
- /*<= /span>
- * Found d= omain(s), now convert them:
- * - prefix each domain with a dot
- * - convert comma separated= list to MULTI_SZ
- = */
- = PWCHAR pos =3D domains;
- while (TRUE)
- {
- = /* Terminate the domain at the next comma */
- PWCHAR comma =3D wcsc= hr(pos, ',');

-= if (comma)
- {
= - *comma =3D '\0';
- }
-
- = DWORD domain_len =3D (DWORD)wcslen(pos);
- DWORD domain_size =3D dom= ain_len * glyph_size;
-= DWORD converted_size =3D (DWORD)(pos - domains) * glyph_siz= e;
-
- /* Ignore itf domains wh= ich match a pushed search domain */
- if (ListContainsDomain(search_domains, pos, d= omain_len))
- = {
- = if (comma)
- = {
- = /* Overwrite the ignored domain with remaining one(s) */=
- = memmove(pos, comma + 1, buf_size - converted_size);
- *size -=3D domain_= size + glyph_size;
- = continue;
- }
- else
- {
- /* This was the last domain */- *pos = =3D '\0';
- = *size -=3D domain_size;
- return wcslen(domains) ? NO_E= RROR : ERROR_FILE_NOT_FOUND;
- }
- }
- /*= Add space for the leading dot */
- domain_len +=3D 1;
- domain_size +=3D glyph_size;
-
- /* Space for the terminating zer= os */
- = const DWORD extra_size =3D 2 * glyph_size;
-
-= /* Check for enough space to convert this domain */<= br>- if (converted= _size + domain_size + extra_size > buf_size)
- {
- /* Domain doesn't fit, bad lu= ck if it's the first one */
- *pos =3D '\0';
- *size =3D converted_siz= e =3D=3D 0 ? 0 : converted_size + glyph_size;
- return ERROR_MORE_DATA;<= br>- }
<= span style=3D"color: hsl(0, 100%, 40%);">-

- /* Prefix domain at pos with the dot *= /
- memm= ove(pos + 1, pos, buf_size - converted_size - glyph_size);
- domains[buf_len - 1] = =3D '\0';
- = *pos =3D '.';
- *size +=3D glyph_size;
-
- if (!comma)
- {
- /* Conversion is done */
- *(pos + domain_len) = =3D '\0';
- = *size +=3D glyph_size;
- return NO_ERROR;
- }
-
- /* Comma pos is now +1 after adding leading dot */
- pos =3D= comma + 2;
- = }
+ retu= rn ConvertItfDnsDomains(search_domains, domains, size, buf_size); }
}

=

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

=
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib517457015b754d59aeb70827c4= 795aa6154728c
Gerrit-Change-Number: 1458
Gerrit-PatchSet: 7
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: d12fk <heiko@...515...>=
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: cron2 <gert@...1296...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --M3diMIkEWEU=--