0
0
mirror of https://github.com/OpenVPN/openvpn.git synced 2024-09-20 03:52:28 +02:00

dco-freebsd: dynamically re-allocate buffer if it's too small

It's possible for the buffer we provide for OVPN_GET_PEER_STATS to be
too small. Handle the error, re-allocate a larger buffer and try again
rather than failing.

Signed-off-by: Kristof Provost <kprovost@netgate.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20240124152739.28248-1-kprovost@netgate.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg28128.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
This commit is contained in:
Kristof Provost 2024-01-24 16:27:39 +01:00 committed by Gert Doering
parent c1e1d132f6
commit 62676935d7

View File

@ -698,7 +698,8 @@ dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m)
{
struct ifdrv drv;
uint8_t buf[4096];
uint8_t *buf = NULL;
size_t buf_size = 4096;
nvlist_t *nvl;
const nvlist_t *const *nvpeers;
size_t npeers;
@ -712,17 +713,28 @@ dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m)
CLEAR(drv);
snprintf(drv.ifd_name, IFNAMSIZ, "%s", dco->ifname);
drv.ifd_cmd = OVPN_GET_PEER_STATS;
drv.ifd_len = sizeof(buf);
retry:
buf = realloc(buf, buf_size);
drv.ifd_len = buf_size;
drv.ifd_data = buf;
ret = ioctl(dco->fd, SIOCGDRVSPEC, &drv);
if (ret && errno == ENOSPC)
{
buf_size *= 2;
goto retry;
}
if (ret)
{
free(buf);
msg(M_WARN | M_ERRNO, "Failed to get peer stats");
return -EINVAL;
}
nvl = nvlist_unpack(buf, drv.ifd_len, 0);
free(buf);
if (!nvl)
{
msg(M_WARN, "Failed to unpack nvlist");