From: "flichtenheld (Code Review)" Date: Tue, 20 Jan 2026 11:50:38 +0000 In-Reply-To: References: Reply-To: frank@...2641..., arne-openvpn@...1227..., heiko@...515..., openvpn-devel@lists.sourceforge.net, gert@...1296... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="2xiGJHIdF8M="; 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: plaisthos , d12fk Cc: openvpn-devel --2xiGJHIdF8M= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello d12fk, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1458?usp=3Demail to look at the new patch set (#6). The change is no longer submittable: checks~ChecksSubmitRule is unsatisfied= now. 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 --- M src/openvpnserv/interactive.c 1 file changed, 101 insertions(+), 72 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/58/1458/6 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: 6 Gerrit-Owner: flichtenheld Gerrit-Reviewer: d12fk Gerrit-Reviewer: plaisthos Gerrit-CC: cron2 Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld --2xiGJHIdF8M= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

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

flichtenheld uploaded patch set #6 to this change.

<= p>View C= hange

The change is no longer submittable: checks~ChecksSubmitRul= e is unsatisfied now.

openvpnserv: Factor out the string c=
onversion from GetItfDnsDomains

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

Change-Id: Ib517457015b754d59aeb70827c4795aa6154728c
Signed-o= ff-by: Frank Lichtenheld <frank@...2641...>
---
M src/openvpnse= rv/interactive.c
1 file changed, 101 insertions(+), 72 deletions(-)
<= br>
git pull ssh://gerrit.openvpn.net:29418/openvpn refs=
/changes/58/1458/6
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(e= s) 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 siz= e is set to 0 and the contents of \p domains
+ * are invalid.
+ * Note that domains are deleted from the string if th= ey match a search domain.
+ *
+ * @param[i= n] search_domains optional list of search domains
+ * @param[in,out] domains buffer= that contains the input comma-separated
+ * string and will cont= ain the MULTI_SZ output string
+ * @param[in,out] size pointer to size of the input s= tring in bytes. Will be
+ * set to the size of the string returne= d, including
+ * = the terminating zeros or 0.
+ * @param[in] buf_size size o= f the \p domains buffer
+ *
+ * @return LS= TATUS NO_ERROR if the domain suffix(es) were read successfully,
<= span style=3D"color: hsl(120, 100%, 40%);">+ * ERROR_FILE_NOT_FOUND= if no domain was found for the interface,

+ * ERROR_MORE_DATA if the list did not fit i= nto the buffer
+ */
+static LSTATUS=
+ConvertItfDnsDomains(PCWST= R search_domains, PWSTR domains, PDWORD size, const DWORD buf_size)<= br>+{
+ const DWORD glyph_size =3D sizeof(*domain= s);
+ const DWORD = buf_len =3D buf_size / glyph_size;
+
+ = /*
+ * Found doma= in(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;
<= span style=3D"color: hsl(120, 100%, 40%);">+

+ /* Ignore itf domains which match a pushed= search domain */
+ = if (ListContainsDomain(search_domains, pos, domain_len))
+ {

+ if (comma)
+ {
+ /* Overwrite the ignored dom= ain with remaining one(s) */
+ memmove(pos, comma + 1, buf_size - converted_size)= ;
+ *s= ize -=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;
<= br>+ domain_size +=3D gl= yph_size;
++ /* Space for the term= inating 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 th= e first one */
+ = *pos =3D '\0';
+ *size =3D converted_size =3D=3D 0 ? 0 : converted_siz= e + glyph_size;
+ = return ERROR_MORE_DATA;
+ }
+
+ /* Prefix= domain at pos with the dot */
+ memmove(pos + 1, pos, buf_size - converted_size - glyph_= size);
+ domai= ns[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;
+ }
+<= br>+ /* Comma pos is now= +1 after adding leading dot */
+ pos =3D comma + 2;
+ }
+}
+
+/**

* Return i= nterface 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_FI= LE_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&quo= t;, L"Domain", L"DhcpDomainSearchList", L"DhcpDoma= in", 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, (PBYTE= )domains, size);
if (!err && *size > gl= yph_size && domains[(*size / glyph_size) - 1] =3D=3D '\0' &= amp;& wcschr(domains, '.'))
{- /*
- * Found domain(s), now c= onvert 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 * gly= ph_size;
- = DWORD converted_size =3D (DWORD)(pos - domains) * glyph_size;
= -
- /* Ignore itf domains which match a p= ushed search domain */
= - if (ListContainsDomain(search_domains, pos, domain_len))
- {
- if (com= ma)
- = {
- = /* Overwrite the ignored domain with remaining one(s) */
- memmove(po= s, comma + 1, buf_size - converted_size);

- *size -=3D domain_size + glyph_= size;
- = continue;
- = }
- = else
- = {
- = /* This was the last domain */
- *pos =3D '\0= 9;;
- = *size -=3D domain_size;
- return wcslen(domains) ? NO_ERROR : ERROR_F= ILE_NOT_FOUND;
- = }
- = }
-
= - /* Add space for= the leading dot */
- = domain_len +=3D 1;
- domain_size +=3D glyph_size;
-
- /* Space for the terminating zeros */- const DWORD ex= tra_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, p= os, buf_size - converted_size - glyph_size);

- domains[buf_len - 1] =3D '\0'= ;;
- *po= s =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 ConvertItfDnsD= omains(search_domains, domains, size, buf_size);

}=
}


=

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

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib517457015b754d59aeb70827c4= 795aa6154728c
Gerrit-Change-Number: 1458
Gerrit-PatchSet: 6
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>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
= --2xiGJHIdF8M=--