From: "d12fk (Code Review)" Date: Fri, 14 Mar 2025 04:21:54 +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="f6BAtUTXwHI="; charset=UTF-8 Subject: [Openvpn-devel] [XS] Change in openvpn[master]: win: calculate address string buffer size List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --f6BAtUTXwHI= 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/+/908?usp=3Demail to review the following change. Change subject: win: calculate address string buffer size ...................................................................... win: calculate address string buffer size Instead of making the string buffer statically sized for a max. of four addresses, calculate it to hold up to the max number of addresses a dns_cfg_message_t can hold (currently four as well). Improves the code so that it doesn't rely on the addresses never being more than four in the future. Change-Id: I23710b1f5b2122ec1f14465911836c0f0afa9c64 Signed-off-by: Heiko Hund --- M src/openvpnserv/interactive.c 1 file changed, 4 insertions(+), 3 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/908/1 diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index eb3c867..90af02d 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -1866,9 +1866,10 @@ int addr_len =3D msg->addr_len; /* sanity check */ - if (addr_len > _countof(msg->addr)) + const size_t max_addrs =3D _countof(msg->addr); + if (addr_len > max_addrs) { - addr_len =3D _countof(msg->addr); + addr_len =3D max_addrs; } if (!msg->iface.name[0]) /* interface name is required */ @@ -1918,7 +1919,7 @@ if (msg->addr_len > 0) { /* prepare the comma separated address list */ - CHAR addrs[256]; /* large enough to hold four IPv4 / IPv6 address = strings */ + CHAR addrs[max_addrs * 64]; /* 64 is enough for one IPv4/6 address= */ size_t offset =3D 0; for (int i =3D 0; i < addr_len; ++i) { -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/908?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I23710b1f5b2122ec1f14465911836c0f0afa9c64 Gerrit-Change-Number: 908 Gerrit-PatchSet: 1 Gerrit-Owner: d12fk Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --f6BAtUTXwHI= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

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

Vi= ew Change

win: calculate address string buffer size

Instead of m= aking the string buffer statically sized for a max. of
four addresses, c= alculate it to hold up to the max number of addresses
a dns_cfg_message_= t can hold (currently four as well). Improves the code
so that it doesn&= #39;t rely on the addresses never being more than four in
the future.
Change-Id: I23710b1f5b2122ec1f14465911836c0f0afa9c64
Signed-off-by:= Heiko Hund <heiko@...2662...>
---
M src/openvpnserv/interactiv= e.c
1 file changed, 4 insertions(+), 3 deletions(-)

git pull s=
sh://gerrit.openvpn.net:29418/openvpn refs/changes/08/908/1
diff --=
git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c<=
br>index eb3c867..90af02d 100644
--- a/src/openvpnser= v/interactive.c
+++ b/src/openvpnserv/interactive.c<= br>@@ -1866,9 +1866,10 @@
int addr_len =3D msg-&= gt;addr_len;

/* sanity check */
- if (addr_len > _cou= ntof(msg->addr))
+= const size_t max_addrs =3D _countof(msg->addr);
+ if (addr_len > max_addrs)<= br> {
- = addr_len =3D _countof(msg->addr);
+ addr_len =3D max_addrs;
}

if (!msg->iface.name[0]) /* interf= ace name is required */
@@ -1918,7 +1919,7 @@
if (msg->addr_len > 0)

{
/* prepare the comma separated address list */

- CHAR addrs[256]; /* large enough= to hold four IPv4 / IPv6 address strings */
+ CHAR addrs[max_addrs * 64]; /* 64 is enoug= h for one IPv4/6 address */
size_t offset =3D 0;
for (int i =3D 0; i < addr_len; ++i)
<= span> {


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

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I23710b1f5b2122ec1f144659118= 36c0f0afa9c64
Gerrit-Change-Number: 908
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...>
Gerrit-MessageType: newchange
--f6BAtUTXwHI=--