From: "flichtenheld (Code Review)" Date: Wed, 7 Jan 2026 17:58:06 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <49908b3b04cda3ea0a76c4724a4da914c19170b3-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="uARw2AlaRiA="; 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 Cc: openvpn-devel --uARw2AlaRiA= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos. Hello plaisthos, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1458?usp=3Demail to review the following change. 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(+), 71 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/58/1458/1 diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index 8b418ce..f30394a 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -2143,6 +2143,106 @@ } =20 /** + * 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. @@ -2183,77 +2283,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: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ib517457015b754d59aeb70827c4795aa6154728c Gerrit-Change-Number: 1458 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --uARw2AlaRiA= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: plaisthos.

flichtenheld would like plaisthos to review this change.

V= iew Change

openvpnserv: Factor out the string conversi=
on from GetItfDnsDomains

Mostly so that we can actually test it. Sin= ce that
code does some in-place conversions a test would be
good.
=
Change-Id: Ib517457015b754d59aeb70827c4795aa6154728c
Signed-off-by: = Frank Lichtenheld <frank@...2641...>
---
M src/openvpnserv/inte= ractive.c
1 file changed, 101 insertions(+), 71 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/change=
s/58/1458/1
diff --git a/src/openvpnserv/interactive.c b/src/openvp=
nserv/interactive.c
index 8b418ce..f30394a 100644--- a/src/openvpnserv/interactive.c
+++ b/src/openvp= nserv/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 se= t to 0 and the contents of \p domains
+ * are invalid.
+ * Note that domains are deleted from the string if they matc= h a search domain.
+ = *
+ * @param[in] = search_domains optional list of search domains
+ * @param[in,out] domains buffer that c= ontains the input comma-separated
+ * string and will contain the= MULTI_SZ output string
+ * @param[in,out] size pointer to size of the input string i= n bytes. Will be
+ * = set to the size of the string returned, incl= uding
+ * = the terminating zeros or 0.
+ * @param[in] buf_size size of the \= p domains buffer
+ *<= /span>
+ * @return LSTATUS N= O_ERROR if the domain suffix(es) were read successfully,
+ * 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 searc= h_domains, PWSTR domains, PDWORD size, const 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)
<= span style=3D"color: hsl(120, 100%, 40%);">+ {

+ /* Terminate the domain at the next c= omma */
+ PWCH= AR comma =3D wcschr(pos, ',');
+ if (comma)
+ {
+ *comma =3D '\0';
+ }
+
+ = DWORD domain_len =3D (DWORD)wcslen(pos);
+ DWORD domain_size =3D domain_len * glyph_s= ize;
+ DWORD c= onverted_size =3D (DWORD)(pos - domains) * glyph_size;
+
+ /* Ignore itf domains which match a pushed search d= omain */
+ if = (ListContainsDomain(search_domains, pos, domain_len))
+ {
+ if (comma)
+ {
+ /* Overwrite the ignored domain with r= emaining one(s) */
+ = memmove(pos, comma + 1, buf_size - converted_size);+ *size -=3D d= omain_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 zer= os */
+ const = DWORD extra_size =3D 2 * glyph_size;
+
+ = /* Check for enough space to convert this domain */
+ if (converted_size + domain_s= ize + 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_s= ize;
+ ret= urn 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';
+ *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 a= dding leading dot */
= + pos =3D comma + 2;
+ }
+}
+
+/**
* Return interface = specific domain suffix(es)
*
* The \p d= omains paramter will be set to a MULTI_SZ domains string.
@= @ -2183,77 +2283,7 @@
err =3D RegGetValueW(itf, NU= LL, values[i], RRF_RT_REG_SZ, NULL, (PBYTE)domains, size);
= if (!err && *size > glyph_size && domains[(*siz= e / glyph_size) - 1] =3D=3D '\0' && wcschr(domains, '.&= #39;))
{
- /*
- * 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 n= ext comma */
- = PWCHAR comma =3D wcschr(pos, ',');
- if (comma)
- {
- *comma =3D '\0';
- }

-
- DWORD domain_len =3D (DWORD)wcsl= en(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 */
<= span style=3D"color: hsl(0, 100%, 40%);">- if (ListContainsD= omain(search_domains, pos, domain_len))
- {
- if (comma)
- {
- /* Overwrite the ignored dom= ain 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;
- re= turn wcslen(domains) ? NO_ERROR : ERROR_FILE_NOT_FOUND;
- }
- }
-
- /* Add space for the leading dot */
- domain_len +=3D 1;=

- domai= n_size +=3D glyph_size;
-
- /* = Space for the terminating zeros */
- const DWORD extra_size =3D 2 * glyph_size;

-
- /* Check for enough space to c= onvert this domain */
-= if (converted_size + domain_size + extra_size > buf_size= )
- {
- /* D= omain 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;
- ret= urn ERROR_MORE_DATA;
- = }
-
- /* Prefix = domain at pos with the dot */
- memmove(pos + 1, pos, buf_size - converted_size - g= lyph_size);
- = domains[buf_len - 1] =3D '\0';
- *pos =3D '.';
- *size +=3D glyph_siz= e;

-
- if (!comma)
- {

- /* Conversion is d= one */
- = *(pos + domain_len) =3D '\0';
- *size +=3D glyph_size;
<= span style=3D"color: hsl(0, 100%, 40%);">- return NO_ERR= OR;
- }<= /span>
-
- /* Comma pos is now +1 afte= r adding leading dot */
- pos =3D comma + 2;
- }
+ return ConvertItfDnsDomains(search_domains, domains, s= ize, buf_size);
}
}

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

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib517457015b754d59aeb70827c4= 795aa6154728c
Gerrit-Change-Number: 1458
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
= --uARw2AlaRiA=--