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>
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 */
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)
{