git: c24b1d9359b8 - main - pfctl: handle errors from PFNL_CMD_GETSTATES

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Tue, 05 May 2026 21:26:20 UTC
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=c24b1d9359b899c7532d5b296f37cf3d74a36942

commit c24b1d9359b899c7532d5b296f37cf3d74a36942
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2026-05-05 16:57:25 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2026-05-05 20:20:42 +0000

    pfctl: handle errors from PFNL_CMD_GETSTATES
    
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 lib/libpfctl/libpfctl.c | 2 +-
 sbin/pfctl/pfctl.c      | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c
index 59783592a370..ac60a924c228 100644
--- a/lib/libpfctl/libpfctl.c
+++ b/lib/libpfctl/libpfctl.c
@@ -2009,7 +2009,7 @@ pfctl_get_states_h(struct pfctl_handle *h, struct pfctl_state_filter *filter, pf
 			return (ret);
 	}
 
-	return (0);
+	return (e.error);
 }
 
 int
diff --git a/sbin/pfctl/pfctl.c b/sbin/pfctl/pfctl.c
index e84e7f9272d4..f35baf25ec35 100644
--- a/sbin/pfctl/pfctl.c
+++ b/sbin/pfctl/pfctl.c
@@ -1991,6 +1991,7 @@ pfctl_show_states(int dev, const char *iface, int opts)
 {
 	struct pfctl_show_state_arg arg;
 	struct pfctl_state_filter filter = {};
+	int ret;
 
 	if (iface != NULL)
 		strlcpy(filter.ifname, iface, IFNAMSIZ);
@@ -1999,8 +2000,8 @@ pfctl_show_states(int dev, const char *iface, int opts)
 	arg.dotitle = opts & PF_OPT_SHOWALL;
 	arg.iface = iface;
 
-	if (pfctl_get_states_h(pfh, &filter, pfctl_show_state, &arg))
-		return (-1);
+	if ((ret = pfctl_get_states_h(pfh, &filter, pfctl_show_state, &arg)) != 0)
+		errc(1, ret, "pfctl_get_states");
 
 	return (0);
 }