]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
win: calculate address string buffer size
authorHeiko Hund <heiko@ist.eigentlich.net>
Mon, 24 Mar 2025 08:33:44 +0000 (09:33 +0100)
committerGert Doering <gert@greenie.muc.de>
Mon, 24 Mar 2025 09:16:47 +0000 (10:16 +0100)
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 <heiko@ist.eigentlich.net>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Message-Id: <20250324083350.4019-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg31196.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpnserv/interactive.c

index 50363b6653f599b647879fc76e8dde704c0685b4..e64ac30176663071e9469ecef1f450aa1e6d1fc2 100644 (file)
@@ -1848,9 +1848,10 @@ HandleDNSConfigMessage(const dns_cfg_message_t *msg, undo_lists_t *lists)
     int addr_len = msg->addr_len;
 
     /* sanity check */
-    if (addr_len > _countof(msg->addr))
+    const size_t max_addrs = _countof(msg->addr);
+    if (addr_len > max_addrs)
     {
-        addr_len = _countof(msg->addr);
+        addr_len = max_addrs;
     }
 
     if (!msg->iface.name[0]) /* interface name is required */
@@ -1900,7 +1901,7 @@ HandleDNSConfigMessage(const dns_cfg_message_t *msg, undo_lists_t *lists)
     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 = 0;
         for (int i = 0; i < addr_len; ++i)
         {