]> git.feebdaed.xyz Git - 0xmirror/openvpn.git/commitdiff
iservice: fix calculation of converted domains size
authorHeiko Hund <heiko@ist.eigentlich.net>
Wed, 26 Nov 2025 10:34:21 +0000 (11:34 +0100)
committerGert Doering <gert@greenie.muc.de>
Wed, 26 Nov 2025 10:57:56 +0000 (11:57 +0100)
To keep track of how much of the buffer is already used, the difference
of the current position and the start of the buffer needs to be
multiplied with the size of a character / glyph to bet the byte count,
with which calculations are done further down below.

Reported-by: Marc Heuse <marc@srlabs.de>
Reported-by: stephan@srlabs.de
Change-Id: I16f9426e57f4802ba038ab51f5b70161464b9428
Signed-off-by: Heiko Hund <heiko@ist.eigentlich.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1390
Message-Id: <20251126103427.4085-1-gert@greenie.muc.de>
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpnserv/interactive.c

index dbb5a4b38d2c992415cf6407be14daad4269fefd..ed3c92891abaf91afc18af346ba64897b066d372 100644 (file)
@@ -2181,8 +2181,11 @@ GetItfDnsDomains(HKEY itf, PCWSTR search_domains, PWSTR domains, PDWORD size)
                     *comma = '\0';
                 }
 
-                /* Ignore itf domains which match a pushed search domain */
                 size_t domain_len = wcslen(pos);
+                size_t domain_size = domain_len * one_glyph;
+                size_t converted_size = (pos - domains) * one_glyph;
+
+                /* Ignore itf domains which match a pushed search domain */
                 if (ListContainsDomain(search_domains, pos, domain_len))
                 {
                     if (comma)
@@ -2199,11 +2202,14 @@ GetItfDnsDomains(HKEY itf, PCWSTR search_domains, PWSTR domains, PDWORD size)
                     }
                 }
 
-                /* Check for enough space to convert this domain */
-                domain_len += 1; /* leading dot */
-                size_t converted_size = pos - domains;
-                size_t domain_size = domain_len * one_glyph;
+                /* Add space for the leading dot */
+                domain_len += 1;
+                domain_size += one_glyph;
+
+                /* Space for the terminating zeros */
                 size_t extra_size = 2 * one_glyph;
+
+                /* 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 */