aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKristof Provost <kp@FreeBSD.org>2023-11-17 09:14:59 +0000
committerKristof Provost <kp@FreeBSD.org>2023-11-24 09:19:04 +0000
commit3b0e5375ca85124a1684ae22b9ef5872ea0f5278 (patch)
tree5adb27424c95046e52cd4413ade7889dcf6bbe7b /lib
parentecb4d2c6e1d8685c02e730e8986400a52403d8d3 (diff)
downloadsrc-3b0e5375ca85124a1684ae22b9ef5872ea0f5278.tar.gz
src-3b0e5375ca85124a1684ae22b9ef5872ea0f5278.zip
libpfctl: handle allocation failure
While it's unlikely for userspace to fail to allocate memory it is still possible. Handle malloc() returning NULL. Reported by: Bill Meeks <bill@themeeks.net> MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 33d55d0d0f33787e9e2796b5000be73af42573bc)
Diffstat (limited to 'lib')
-rw-r--r--lib/libpfctl/libpfctl.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c
index 7fc22734994b..e5675f2a232b 100644
--- a/lib/libpfctl/libpfctl.c
+++ b/lib/libpfctl/libpfctl.c
@@ -71,6 +71,11 @@ pfctl_do_ioctl(int dev, uint cmd, size_t size, nvlist_t **nvl)
retry:
nv.data = malloc(size);
+ if (nv.data == NULL) {
+ ret = ENOMEM;
+ goto out;
+ }
+
memcpy(nv.data, data, nvlen);
nv.len = nvlen;
@@ -190,6 +195,8 @@ _pfctl_get_status_counters(const nvlist_t *nvl,
struct pfctl_status_counter *c;
c = malloc(sizeof(*c));
+ if (c == NULL)
+ continue;
c->id = ids[i];
c->counter = counts[i];