diff options
author | Kristof Provost <kp@FreeBSD.org> | 2023-10-23 11:43:52 +0000 |
---|---|---|
committer | Kristof Provost <kp@FreeBSD.org> | 2023-10-24 07:50:31 +0000 |
commit | 2cffb52514b070e716e700c7f58fdb8cd9b05335 (patch) | |
tree | af0d6bbc8241c1a18e509e117405b416c478ab7b | |
parent | 82ea0132c8b17a7a6067c8a36c6434e587ede6de (diff) | |
download | src-2cffb52514b070e716e700c7f58fdb8cd9b05335.tar.gz src-2cffb52514b070e716e700c7f58fdb8cd9b05335.zip |
libpfctl: fix pfctl_do_ioctl()
pfctl_do_ioctl() copies the packed request data into the request buffer
and then frees it. However, it's possible for the buffer to be too small
for the reply, causing us to allocate a new buffer. We then copied from
the freed request, and freed it again.
Do not free the request buffer until we're all the way done.
PR: 274614
Reviewed by: emaste
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D42329
-rw-r--r-- | lib/libpfctl/libpfctl.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c index 0360c0c63be7..22b0471e2912 100644 --- a/lib/libpfctl/libpfctl.c +++ b/lib/libpfctl/libpfctl.c @@ -79,7 +79,6 @@ pfctl_do_ioctl(int dev, uint cmd, size_t size, nvlist_t **nvl) retry: nv.data = malloc(size); memcpy(nv.data, data, nvlen); - free(data); nv.len = nvlen; nv.size = size; @@ -97,13 +96,15 @@ retry: if (ret == 0) { *nvl = nvlist_unpack(nv.data, nv.len, 0); if (*nvl == NULL) { - free(nv.data); - return (EIO); + ret = EIO; + goto out; } } else { ret = errno; } +out: + free(data); free(nv.data); return (ret); |